Skip to content

Commit f499d22

Browse files
committed
create list, remove, and update funcs
1 parent 2c847b4 commit f499d22

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

R/list.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#' List Installed Quarto extensions
2+
#'
3+
#' List Quarto Extensions in this folder or project by running `quarto list`
4+
#'
5+
#' # Extension Trust
6+
#'
7+
#' Quarto extensions may execute code when documents are rendered. Therefore, if
8+
#' you do not trust the author of an extension, we recommend that you do not
9+
#' install or use the extension.
10+
#'
11+
#' @inheritParams quarto_render
12+
#'
13+
#' @examples
14+
#' \dontrun{
15+
#' # List Quarto Extensions in this folder or project
16+
#' quarto_list_extensions()
17+
#' }
18+
#'
19+
#' @importFrom rlang is_interactive
20+
#' @importFrom cli cli_abort
21+
#' @export
22+
quarto_list_extensions <- function(quiet = FALSE, quarto_args = NULL){
23+
quarto_bin <- find_quarto()
24+
25+
args <- c("extensions", if (quiet) cli_arg_quiet(), quarto_args)
26+
x <- quarto_list(args, quarto_bin = quarto_bin, echo = TRUE)
27+
# Clean the stderr output to remove extra spaces and ensure consistent formatting
28+
stderr_cleaned <- gsub("\\s+$", "", x$stderr)
29+
if (grepl("No extensions are installed", stderr_cleaned)) {
30+
invisible()
31+
} else{
32+
invisible(read.table(text = stderr_cleaned, header = TRUE, fill = TRUE, sep = "", stringsAsFactors = FALSE))
33+
}
34+
}
35+
36+
quarto_list <- function(args = character(), ...){
37+
quarto_run_what("list", args = args, ...)
38+
}

R/remove.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#' Remove a Quarto extensions
2+
#'
3+
#' Remove an extension in this folder or project by running `quarto remove`
4+
#'
5+
#' # Extension Trust
6+
#'
7+
#' Quarto extensions may execute code when documents are rendered. Therefore, if
8+
#' you do not trust the author of an extension, we recommend that you do not
9+
#' install or use the extension.
10+
#' By default `no_prompt = FALSE` which means that
11+
#' the function will ask for explicit approval when used interactively, or
12+
#' disallow installation.
13+
#'
14+
#' @inheritParams quarto_render
15+
#'
16+
#' @param extension The extension to remove, either an archive or a GitHub
17+
#' repository as described in the documentation
18+
#' <https://quarto.org/docs/extensions/managing.html>.
19+
#'
20+
#' @param no_prompt Do not prompt to confirm approval to download external extension.
21+
#'
22+
#' @examples
23+
#' \dontrun{
24+
#' # Remove an already installed extension
25+
#' quarto_remove_extension("quarto-ext/fontawesome")
26+
#'
27+
#' @importFrom rlang is_interactive
28+
#' @importFrom cli cli_abort
29+
#' @export
30+
quarto_remove_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
31+
rlang::check_required(extension)
32+
33+
quarto_bin <- find_quarto()
34+
35+
# This will ask for approval or stop installation
36+
approval <- check_removal_approval(no_prompt, extension, "https://quarto.org/docs/extensions/managing.html")
37+
38+
if (approval) {
39+
args <- c(extension, "--no-prompt", if (quiet) cli_arg_quiet(), quarto_args)
40+
quarto_remove(args, quarto_bin = quarto_bin, echo = TRUE)
41+
}
42+
43+
invisible()
44+
}
45+
46+
quarto_remove <- function(args = character(), ...) {
47+
quarto_run_what("remove", args = args, ...)
48+
}

R/update.R

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#' Update a Quarto extensions
2+
#'
3+
#' Update an extension to this folder or project by running `quarto update`
4+
#'
5+
#' # Extension Trust
6+
#'
7+
#' Quarto extensions may execute code when documents are rendered. Therefore, if
8+
#' you do not trust the author of an extension, we recommend that you do not
9+
#' install or use the extension.
10+
#' By default `no_prompt = FALSE` which means that
11+
#' the function will ask for explicit approval when used interactively, or
12+
#' disallow installation.
13+
#'
14+
#' @inheritParams quarto_render
15+
#'
16+
#' @param extension The extension to install, either an archive or a GitHub
17+
#' repository as described in the documentation
18+
#' <https://quarto.org/docs/extensions/managing.html>.
19+
#'
20+
#' @param no_prompt Do not prompt to confirm approval to download external extension.
21+
#'
22+
#' @examples
23+
#' \dontrun{
24+
#' # Update a template and set up a draft document from a GitHub repository
25+
#' quarto_update_extension("quarto-ext/fontawesome")
26+
#'
27+
#' # Update a template and set up a draft document from a ZIP archive
28+
#' quarto_update_extension("https://github.com/quarto-ext/fontawesome/archive/refs/heads/main.zip")
29+
#' }
30+
#'
31+
#' @importFrom rlang is_interactive
32+
#' @importFrom cli cli_abort
33+
#' @export
34+
quarto_update_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
35+
rlang::check_required(extension)
36+
37+
quarto_bin <- find_quarto()
38+
39+
# This will ask for approval or stop installation
40+
approval <- check_extension_approval(no_prompt, "Quarto extensions", "https://quarto.org/docs/extensions/managing.html")
41+
42+
if (approval) {
43+
args <- c(extension, "--no-prompt", if (quiet) cli_arg_quiet(), quarto_args)
44+
quarto_update(args, quarto_bin = quarto_bin, echo = TRUE)
45+
}
46+
47+
invisible()
48+
}
49+
50+
quarto_update <- function(args = character(), ...) {
51+
quarto_run_what("update", args = args, ...)
52+
}

0 commit comments

Comments
 (0)