Skip to content

Commit

Permalink
Not all function support --quiet in quarto CLI
Browse files Browse the repository at this point in the history
So keep adding it in wrapper function instead, but handle the option overwrite in checking for the arg

Revert f423a89
  • Loading branch information
cderv committed Jul 23, 2024
1 parent 1a2359f commit 1cd9380
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ quarto_add_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FA
approval <- check_extension_approval(no_prompt, "Quarto extensions", "https://quarto.org/docs/extensions/managing.html")

if (approval) {
args <- c(extension, "--no-prompt", if (quiet) cli_arg_quiet(), quarto_args)
args <- c(extension, "--no-prompt", if (is_quiet(quiet)) cli_arg_quiet(), quarto_args)
quarto_add(args, quarto_bin = quarto_bin, echo = TRUE)
}

Expand Down
2 changes: 1 addition & 1 deletion R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ quarto_create_project <- function(name, type = "default", dir = ".", no_prompt =

quarto_bin <- find_quarto()

args <- c("project", type, name, "--no-prompt", "--no-open", if (quiet) cli_arg_quiet(), quarto_args = NULL)
args <- c("project", type, name, "--no-prompt", "--no-open", if (is_quiet(quiet)) cli_arg_quiet(), quarto_args = NULL)

owd <- setwd(dir)
on.exit(setwd(owd), add = TRUE, after = FALSE)
Expand Down
4 changes: 3 additions & 1 deletion R/inspect.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ quarto_inspect <- function(input = ".",
args <- c(args, c("--profile", paste0(profile, collapse = ",")))
}

if (is_quiet(quiet)) args <- cli_arg_quiet(args)

args <- c(args, quarto_args)

res <- quarto_run(args, quiet = isTRUE(quiet), quarto_bin = quarto_bin)
res <- quarto_run(args, quarto_bin = quarto_bin)

fromJSON(res$stdout)
}
7 changes: 7 additions & 0 deletions R/quarto-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ cli_arg_profile <- function(profile, ...) {
append_cli_args(arg, ...)
}

is_quiet <- function(quiet) {
# this option takes precedence
quiet_options <- getOption("quarto.quiet", NA)
if (!is.na(quiet_options)) return(quiet_options)
isTRUE(quiet)
}

cli_arg_quiet <- function(...) {
append_cli_args("--quiet", ...)
}
Expand Down
12 changes: 3 additions & 9 deletions R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ quarto_version <- function() {
}

#' @importFrom processx run
quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FALSE, echo_cmd = getOption("quarto.echo_cmd", FALSE), quiet = FALSE, ..., .call = rlang::caller_env()) {
# this option takes precedence
if (!is.na(getOption("quarto.quiet", NA))) quiet <- getOption("quarto.quiet", NA)
# if quiet, add the flag to quarto call
if (quiet) {
if (!cli_arg_quiet() %in% args) args <- cli_arg_quiet(args)
}
quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FALSE, echo_cmd = getOption("quarto.echo_cmd", FALSE), ..., .call = rlang::caller_env()) {
res <- tryCatch(
{
processx::run(quarto_bin, args = args, echo = echo, error_on_status = TRUE, echo_cmd = echo_cmd, ...)
Expand All @@ -67,8 +61,8 @@ quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FA
invisible(res)
}

quarto_run_what <- function(what = character(), args = character(), quarto_bin = find_quarto(), echo = FALSE, quiet = FALSE, ..., .call = rlang::caller_env()) {
res <- quarto_run(quarto_bin, args = c(what, args), echo = echo, quiet = quiet, ..., .call = .call)
quarto_run_what <- function(what = character(), args = character(), quarto_bin = find_quarto(), echo = FALSE, ..., .call = rlang::caller_env()) {
res <- quarto_run(quarto_bin, args = c(what, args), echo = echo, ..., .call = .call)
invisible(res)
}

Expand Down
9 changes: 5 additions & 4 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
#' override metadata. This will be merged with `metadata` if both are
#' specified, with low precedence on `metadata` options.
#' @param debug Leave intermediate files in place after render.
#' @param quiet Suppress warning and other messages. `quarto.quiet` R options
#' will take precedence in any rendering, which is useful to have verbose
#' logging in pkgdown for example.
#' @param quiet Suppress warning and other messages.
#' @param profile [Quarto project
#' profile(s)](https://quarto.org/docs/projects/profiles.html) to use. Either
#' a character vector of profile names or `NULL` to use the default profile.
Expand Down Expand Up @@ -176,6 +174,9 @@ quarto_render <- function(input = NULL,
if (isTRUE(debug)) {
args <- c(args, "--debug")
}
if (is_quiet(quiet)) {
args <- cli_arg_quiet(args)
}
if (!is.null(profile)) {
args <- cli_arg_profile(profile, args)
}
Expand All @@ -187,7 +188,7 @@ quarto_render <- function(input = NULL,
}

# run quarto
quarto_run(args, echo = TRUE, quiet = isTRUE(quiet), quarto_bin = quarto_bin)
quarto_run(args, echo = TRUE, quarto_bin = quarto_bin)

# no return value
invisible(NULL)
Expand Down
2 changes: 1 addition & 1 deletion R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ quarto_use_template <- function(template, no_prompt = FALSE, quiet = FALSE, quar
# TODO: Change if / when https://github.com/quarto-dev/quarto-cli/issues/8438
args <- c("template", template, "--no-prompt", quarto_args)

if (quarto_version() > "1.5.4" & isTRUE(quiet)) {
if (quarto_version() > "1.5.4" && is_quiet(quiet)) {
args <- cli_arg_quiet(args)
}

Expand Down
4 changes: 1 addition & 3 deletions man/quarto_add_extension.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/quarto_create_project.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/quarto_inspect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/quarto_render.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Code
quarto_render("input.qmd", quiet = TRUE, quarto_args = c("--to", "native"))
Output
Running <quarto full path> render input.qmd --to native --quiet
Running <quarto full path> render input.qmd --quiet --to native

16 changes: 16 additions & 0 deletions tests/testthat/test-quarto-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ test_that("create quiete arg", {
expect_identical(cli_arg_quiet(), c("--quiet"))
expect_identical(cli_arg_quiet("input.qmd"), c("input.qmd", "--quiet"))
})

test_that("quarto.quiet options takes over", {
expect_identical(is_quiet(TRUE), TRUE)
expect_identical(is_quiet(FALSE), FALSE)
expect_identical(is_quiet(NA), FALSE)
withr::with_options(list(quarto.quiet = TRUE), {
expect_identical(is_quiet(TRUE), TRUE)
expect_identical(is_quiet(FALSE), TRUE)
expect_identical(is_quiet(NA), TRUE)
})
withr::with_options(list(quarto.quiet = FALSE), {
expect_identical(is_quiet(TRUE), FALSE)
expect_identical(is_quiet(FALSE), FALSE)
expect_identical(is_quiet(NA), FALSE)
})
})
7 changes: 0 additions & 7 deletions tests/testthat/test-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ test_that("quarto CLI sitrep", {
)
})

test_that("quiet is handled in quarto run directly", {
skip_if_no_quarto()
skip_on_cran()
qmd <- local_qmd_file("content")
expect_output(quarto_run(c("render", qmd), echo = TRUE, quiet = TRUE), regexp = NA)
expect_output(quarto_run(c("render", qmd, "--quiet"), echo = TRUE), regexp = NA)
})

test_that("quarto.quiet options controls echo and overwrite function argument", {
skip_if_no_quarto()
Expand Down

0 comments on commit 1cd9380

Please sign in to comment.