Skip to content

Commit

Permalink
Fix check_extension_approval usage
Browse files Browse the repository at this point in the history
fixes #172
  • Loading branch information
cderv committed Apr 26, 2024
1 parent ba8485a commit 9275b2d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 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.4.1
Version: 1.4.2
Authors@R: c(
person("JJ", "Allaire", , "jj@posit.co", role = "aut",
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)

- Approval check in `quarto_add_extension()` and `quarto_use_template()` now works correctly (thanks, @eveyp, #172).

# quarto 1.4

- This version is now adapted to Quarto 1.4 latest stable release.
Expand Down
9 changes: 5 additions & 4 deletions R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ quarto_add_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FA
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")
approval <- check_extension_approval(no_prompt, "Quarto extensions", "https://quarto.org/docs/extensions/managing.html")

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

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

invisible()
}
Expand Down
20 changes: 12 additions & 8 deletions R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ quarto_use_template <- function(template, no_prompt = FALSE, quiet = FALSE, quar
quarto_bin <- find_quarto()

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

# quarto use template does not support `--quiet` so we mimic it by suppressing `echo` in processx
# TODO: Change if / when https://github.com/quarto-dev/quarto-cli/issues/8438
args <- c("template", template, "--no-prompt", quarto_args)
if (approval) {

if (quarto_version() > "1.5.4" & isTRUE(quiet)) {
args <- cli_arg_quiet(args)
}
# quarto use template does not support `--quiet` so we mimic it by suppressing `echo` in processx
# 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)) {
args <- cli_arg_quiet(args)
}

quarto_use(args, quarto_bin = quarto_bin, echo = !quiet)
quarto_use(args, quarto_bin = quarto_bin, echo = !quiet)

}

invisible()
}
Expand Down
36 changes: 18 additions & 18 deletions R/utils-prompt.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
check_extension_approval <- function(no_prompt = FALSE, what = "Something", see_more_at = NULL) {
if (!no_prompt) {
if (!rlang::is_interactive()) {
cli::cli_abort(c(
"{ what } requires explicit approval.",
">" = "Set {.arg no_prompt = TRUE} if you agree.",
if (!is.null(see_more_at)) {
c(i = "See more at {.url {see_more_at}}")
}
))
} else {
cli::cli_inform(c(
"{what} may execute code when documents are rendered. ",
"*" = "If you do not trust the author(s) of this {what}, we recommend that you do not install or use this {what}."
))
prompt_value <- tolower(readline(sprintf("Do you trust the authors of this %s (Y/n)? ", what)))
if (!prompt_value %in% "y") {
cli::cli_inform("{what} not installed.")
return(invisible(FALSE))
if (no_prompt) return(TRUE)

if (!rlang::is_interactive()) {
cli::cli_abort(c(
"{ what } requires explicit approval.",
">" = "Set {.arg no_prompt = TRUE} if you agree.",
if (!is.null(see_more_at)) {
c(i = "See more at {.url {see_more_at}}")
}
))
} else {
cli::cli_inform(c(
"{what} may execute code when documents are rendered. ",
"*" = "If you do not trust the author(s) of this {what}, we recommend that you do not install or use this {what}."
))
prompt_value <- tolower(readline(sprintf("Do you trust the authors of this %s (Y/n)? ", what)))
if (!prompt_value %in% "y") {
cli::cli_inform("{what} not installed.")
return(invisible(FALSE))
}
}
}

0 comments on commit 9275b2d

Please sign in to comment.