quarto-dev / quarto-r

R interface to quarto-cli
https://quarto-dev.github.io/quarto-r/
146 stars 24 forks source link

Add CLI wrapper for extensions : `list`, `remove`, `update` #188

Open parmsam opened 5 months ago

parmsam commented 5 months ago

Something like

quarto_list_extensions <- function(quarto_args = NULL){
  quarto_bin <- quarto:::find_quarto()

  args <- "extensions"  

  x <- quarto_list(args, quarto_bin = quarto_bin)

  readr::read_table(x$stderr)
}

quarto_list <- function(args = character(), ...){
  quarto:::quarto_run_what("list", args = args, ...)
}
parmsam commented 5 months ago

Similarly could add quarto_remove_extension() and quarto_update_extension(). Here's an attempt at that:

quarto_update_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
  rlang::check_required(extension)

  quarto_bin <- quarto:::find_quarto()

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

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

  invisible()
}

quarto_update <- function(args = character(), ...) {
  quarto:::quarto_run_what("update", args = args, ...)
}
quarto_remove_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
  rlang::check_required(extension)

  quarto_bin <- quarto:::find_quarto()

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

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

  invisible()
}

quarto_remove <- function(args = character(), ...) {
  quarto:::quarto_run_what("remove", args = args, ...)
}
cderv commented 5 months ago

All the wrapper usage are followed at

I have opened some issue to track list remove and update.

I did not add them yet, because this is the kind of task that I would have thought a user did not need R to run. It is done once in a while, and can be done in terminal.

What is your use case in R context for these ?

Here's an attempt at that:

PR are welcome. This is easier to review than code in an issue.

parmsam commented 4 months ago

Thank you for creating those separate issues! I originally had a need for the wrapper functions in this shiny gadget that I recently created to interactively explore and manage Quarto Extensions from the official Listing.

Given that users can add extensions via the R package, it would be beneficial to enable them to list, update, and remove extensions using R as well. I envision this functionality being similar to the R package functions in {utils} (e.g., installed.packages(), update.packages(), remove.packages()), but specifically for Quarto extensions. This would provide a seamless experience for R users, allowing them to manage extensions without needing to switch to the terminal, which can be unfamiliar to some.

Sure! I can create a PR in the next few days. 😄