-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polish quarto_create_project() #206
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
#' Create a quarto project | ||
#' | ||
#' This function calls `quarto create project <type> <name>`. It will create a | ||
#' new directory with the project name and add some skeletons files for the | ||
#' project type chosen. | ||
#' This function calls `quarto create project <type> <name>`. It creates a new | ||
#' directory with the project name, inside the requested parent directory, and | ||
#' adds some starter files that are appropriate to the project type. | ||
#' | ||
#' # Quarto version required | ||
#' | ||
#' This function require Quarto 1.4 or higher. Use [`quarto_version()`]to check | ||
#' the version of Quarto detected. | ||
#' This function requires Quarto 1.4 or higher. Use [quarto_version()] to see | ||
#' your current Quarto version. | ||
#' | ||
#' @param type The type of project to create. As of 1.4, it can be one of | ||
#' @param type The type of project to create. As of Quarto 1.4, it can be one of | ||
#' `r paste0("\\code{", paste(quarto_project_type, collapse = "}, \\code{"),"}")`. | ||
#' @param name The name of the project and the directory that will be created. | ||
#' @param dir The directory where to create the new Quarto project. | ||
#' @param dir The directory in which to create the new Quarto project, i.e. the | ||
#' parent directory. | ||
#' | ||
#' @seealso Quarto documentation on [Quarto projects](https://quarto.org/docs/projects/quarto-projects.html) | ||
#' | ||
#' @inheritParams quarto_render | ||
#' @inheritParams quarto_add_extension | ||
#' @param no_prompt Do not prompt to approve the creation of the new project | ||
#' folder. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' quarto_create_project("my-first-quarto-project", dir = "~/tmp") | ||
#' } | ||
#' | ||
#' | ||
#' @export | ||
quarto_create_project <- function(name, type = "default", dir = ".", no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) { | ||
|
@@ -32,14 +40,14 @@ | |
"This will create a new Quarto {.emph {type}} project as a folder named {.strong {name}} in {.path {xfun::normalize_path(dir)}}." | ||
)) | ||
prompt_value <- tolower(readline(sprintf("Do you want to proceed (Y/n)? "))) | ||
if (!prompt_value %in% "y") { | ||
if (!prompt_value %in% c("", "y")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I see Best reference I can find for this: https://askubuntu.com/a/322601 |
||
cli::cli_abort("Operation aborted.") | ||
} | ||
} | ||
|
||
quarto_bin <- find_quarto() | ||
|
||
args <- c("project", type, name, "--no-prompt", "--no-open", if (is_quiet(quiet)) cli_arg_quiet(), quarto_args = NULL) | ||
args <- c("project", type, name, name, "--no-prompt", "--no-open", if (is_quiet(quiet)) cli_arg_quiet(), quarto_args = NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this, I always get a warning, coming from the quarto cli, with no way to suppress it.
|
||
|
||
owd <- setwd(dir) | ||
on.exit(setwd(owd), add = TRUE, after = FALSE) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
test_that("Create a quarto project", { | ||
skip_if_no_quarto("1.4") | ||
# TODO: Fix the test once issue solve upstream | ||
# - https://github.com/quarto-dev/quarto-cli/issues/8809 | ||
# - https://github.com/quarto-dev/quarto-r/issues/153 | ||
skip_if_quarto("1.5") | ||
Comment on lines
-3
to
-6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With my change re: |
||
expect_snapshot( | ||
error = TRUE, | ||
quarto_create_project() | ||
|
@@ -16,10 +12,6 @@ test_that("Create a quarto project", { | |
|
||
test_that("Create a quarto project in another directory", { | ||
skip_if_no_quarto("1.4") | ||
# TODO: Fix the test once issue solve upstream | ||
# - https://github.com/quarto-dev/quarto-cli/issues/8809 | ||
# - https://github.com/quarto-dev/quarto-r/issues/153 | ||
skip_if_quarto("1.5") | ||
tempdir <- withr::local_tempdir() | ||
curr_wd <- getwd() | ||
expect_no_error(quarto_create_project(name = "test-project", dir = tempdir, quiet = TRUE)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the docs for
no_prompt
are inherited fromquarto_add_extension()
they don't really make sense here.(In
quarto_add_extension()
,no_prompt
means "Do not prompt to confirm approval to download external extension.")