Skip to content

Commit

Permalink
Add a quiet argument to function
Browse files Browse the repository at this point in the history
it sets `--quiet` flag to quarto command
  • Loading branch information
cderv committed Jan 24, 2024
1 parent 7b28b8a commit 003dfb6
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: quarto
Title: R Interface to 'Quarto' Markdown Publishing System
Version: 1.3.5
Version: 1.3.6
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0174-9868")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# quarto (development version)

- Add `quiet` argument to pass `--quiet` to `quarto` CLI commands

- Error message now advises to re-run with `quiet = FALSE` because `quarto_render(quiet = TRUE)` will run `quarto render` in quiet mode (thanks to @gadenbuie, #126, @wlandau, #16).

- **rsconnect** R package dependency has been moved to Suggest to reduce this package's overall number of dependencies. **rsconnect** package is only required for publishing using `quarto_publish_*()` functions. Users will be prompted to install (when in interactive mode) if not installed.
Expand Down
6 changes: 4 additions & 2 deletions R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' the function will ask for explicit approval when used interactively, or
#' disallow installation.
#'
#' @inheritParams quarto_render
#'
#' @param extension The extension to install, either an archive or a GitHub
#' repository as described in the documentation
#' <https://quarto.org/docs/extensions/managing.html>.
Expand All @@ -31,15 +33,15 @@
#' @importFrom rlang is_interactive
#' @importFrom cli cli_abort
#' @export
quarto_add_extension <- function(extension = NULL, no_prompt = FALSE, quarto_args = NULL) {
quarto_add_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
rlang::check_required(extension)

quarto_bin <- find_quarto()

# This will ask for approval or stop installation
check_extension_approval(no_prompt, "Quarto extensions", "https://quarto.org/docs/extensions/managing.html")

args <- c(extension,"--no-prompt", quarto_args)
args <- c(extension,"--no-prompt", if (quiet) cli_arg_quiet(), quarto_args)

quarto_add(args, quarto_bin = quarto_bin, echo = TRUE)

Expand Down
4 changes: 4 additions & 0 deletions R/inspect.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#' @export
quarto_inspect <- function(input = ".",
profile = NULL,
quiet = FALSE,
quarto_args = NULL) {

quarto_bin <- find_quarto()
Expand All @@ -40,7 +41,10 @@ quarto_inspect <- function(input = ".",
args <- c(args, c("--profile", paste0(profile, collapse = ",")))
}

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

args <- c(args, quarto_args)

res <- quarto_run(args, quarto_bin = quarto_bin)

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

cli_arg_quiet <- function(...) {
append_cli_args("--quiet", ...)
}

append_cli_args <- function(new, append_to = NULL, after = length(append_to)) {
if (!is.null(append_to)) return(append(append_to, new, after))
new
Expand Down
2 changes: 1 addition & 1 deletion R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ quarto_run <- function(args = character(), quarto_bin = find_quarto(), echo = FA
error = function(e) {
msg <- c("Error running quarto cli:")
if (nzchar(e$stderr)) msg <- c(msg, "x" = e$stderr)
if ("--quiet" %in% args) msg <- c(msg, "i" = "Rerun with `quiet = FALSE` to see the full error message.")
if (cli_arg_quiet() %in% args) msg <- c(msg, "i" = "Rerun with `quiet = FALSE` to see the full error message.")
rlang::abort(msg, call = .call, parent = e)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ quarto_render <- function(input = NULL,
args <- c(args, "--debug")
}
if (isTRUE(quiet)) {
args <- c(args, "--quiet")
args <- cli_arg_quiet(args)
}
if (!is.null(profile)) {
args <- cli_arg_profile(profile, args)
Expand Down
9 changes: 8 additions & 1 deletion man/quarto_add_extension.Rd

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

4 changes: 3 additions & 1 deletion man/quarto_inspect.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-quarto-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ test_that("create profile arg", {
expect_identical(cli_arg_profile(c("a", "b")), c("--profile", "a,b"))
expect_identical(cli_arg_profile(c("a", "b"), "input.qmd"), c("input.qmd", "--profile", "a,b"))
})

test_that("create quiete arg", {
expect_identical(cli_arg_quiet(), c("--quiet"))
expect_identical(cli_arg_quiet("input.qmd"), c("input.qmd", "--quiet"))
})

0 comments on commit 003dfb6

Please sign in to comment.