Skip to content

Commit f423a89

Browse files
committed
Add quarto.quiet option to allow overriding quiet setting
This is useful to show more verbose message when `quarto_render` is used in other tools like pkgdown
1 parent da62d2c commit f423a89

File tree

9 files changed

+41
-16
lines changed

9 files changed

+41
-16
lines changed

R/inspect.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ quarto_inspect <- function(input = ".",
4141
args <- c(args, c("--profile", paste0(profile, collapse = ",")))
4242
}
4343

44-
if (isTRUE(quiet)) args <- cli_arg_quiet(args)
45-
4644
args <- c(args, quarto_args)
4745

48-
res <- quarto_run(args, quarto_bin = quarto_bin)
46+
res <- quarto_run(args, quiet = isTRUE(quiet), quarto_bin = quarto_bin)
4947

5048
fromJSON(res$stdout)
5149
}

R/quarto.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ quarto_version <- function() {
4747
}
4848

4949
#' @importFrom processx run
50-
quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FALSE, echo_cmd = getOption("quarto.echo_cmd", FALSE), ..., .call = rlang::caller_env()) {
50+
quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FALSE, echo_cmd = getOption("quarto.echo_cmd", FALSE), quiet = FALSE, ..., .call = rlang::caller_env()) {
51+
quiet <- getOption("quarto.quiet", FALSE) || quiet
52+
if (quiet) {
53+
if (!cli_arg_quiet() %in% args) args <- cli_arg_quiet(args)
54+
}
5155
res <- tryCatch(
5256
{
5357
processx::run(quarto_bin, args = args, echo = echo, error_on_status = TRUE, echo_cmd = echo_cmd, ...)
@@ -61,8 +65,8 @@ quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FA
6165
invisible(res)
6266
}
6367

64-
quarto_run_what <- function(what = character(), args = character(), quarto_bin = find_quarto(), echo = FALSE, ..., .call = rlang::caller_env()) {
65-
res <- quarto_run(quarto_bin, args = c(what, args), echo = echo, ..., .call = .call)
68+
quarto_run_what <- function(what = character(), args = character(), quarto_bin = find_quarto(), echo = FALSE, quiet = FALSE, ..., .call = rlang::caller_env()) {
69+
res <- quarto_run(quarto_bin, args = c(what, args), echo = echo, quiet = quiet, ..., .call = .call)
6670
invisible(res)
6771
}
6872

R/render.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
#' override metadata. This will be merged with `metadata` if both are
3838
#' specified, with low precedence on `metadata` options.
3939
#' @param debug Leave intermediate files in place after render.
40-
#' @param quiet Suppress warning and other messages.
40+
#' @param quiet Suppress warning and other messages. `quarto.quiet` R options
41+
#' will take precedence in any rendering, which is useful to have verbose
42+
#' logging in pkgdown for example.
4143
#' @param profile [Quarto project
4244
#' profile(s)](https://quarto.org/docs/projects/profiles.html) to use. Either
4345
#' a character vector of profile names or `NULL` to use the default profile.
@@ -174,9 +176,6 @@ quarto_render <- function(input = NULL,
174176
if (isTRUE(debug)) {
175177
args <- c(args, "--debug")
176178
}
177-
if (isTRUE(quiet)) {
178-
args <- cli_arg_quiet(args)
179-
}
180179
if (!is.null(profile)) {
181180
args <- cli_arg_profile(profile, args)
182181
}
@@ -188,7 +187,7 @@ quarto_render <- function(input = NULL,
188187
}
189188

190189
# run quarto
191-
quarto_run(args, echo = TRUE, quarto_bin = quarto_bin)
190+
quarto_run(args, echo = TRUE, quiet = isTRUE(quiet), quarto_bin = quarto_bin)
192191

193192
# no return value
194193
invisible(NULL)

man/quarto_add_extension.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/quarto_create_project.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/quarto_inspect.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/quarto_render.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/render.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Code
44
quarto_render("input.qmd", quiet = TRUE, quarto_args = c("--to", "native"))
55
Output
6-
Running <quarto full path> render input.qmd --quiet --to native
6+
Running <quarto full path> render input.qmd --to native --quiet
77

tests/testthat/test-quarto.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,19 @@ test_that("quarto CLI sitrep", {
7575
)
7676
)
7777
})
78+
79+
test_that("quiet is handled in quarto run directly", {
80+
skip_if_no_quarto()
81+
skip_on_cran()
82+
qmd <- local_qmd_file("content")
83+
expect_output(quarto_run(c("render", qmd), echo = TRUE, quiet = TRUE), regexp = NA)
84+
expect_output(quarto_run(c("render", qmd, "--quiet"), echo = TRUE), regexp = NA)
85+
})
86+
87+
test_that("quarto.quiet options controls echo and overwrite function argument", {
88+
skip_if_no_quarto()
89+
skip_on_cran()
90+
qmd <- local_qmd_file("content")
91+
withr::local_options(list(quarto.quiet = TRUE))
92+
expect_output(quarto_render(qmd, quiet = FALSE), regexp = NA)
93+
})

0 commit comments

Comments
 (0)