Skip to content

Commit

Permalink
feat: add function for creating all exercises at once @jimgar
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Jan 11, 2024
1 parent 1b3ae11 commit 438e532
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(create_all_exercises)
export(exo_committed_to_main)
export(exo_latest_message)
export(exo_one_small_change)
export(exo_split_changes)
importFrom(rlang,`%||%`)
19 changes: 19 additions & 0 deletions R/create-all.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Create all exercises folder at once
#'
#' But do not open them!
#'
#' @inheritParams exo_one_small_change
#'
#' @return The parent path
#' @export
#'
create_all_exercises <- function(parent_path) {
rlang::local_interactive(FALSE)

funs <- getNamespaceExports("saperlipopette")
funs <- setdiff(funs, "create_all_exercises")
purrr::walk(funs, rlang::exec, parent_path = parent_path)

fs::dir_tree(parent_path)
return(parent_path)
}
7 changes: 7 additions & 0 deletions R/saperlipopette-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
#' @importFrom rlang `%||%`
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
2 changes: 1 addition & 1 deletion R/utils-usethis.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
create_project <- function(path) {
rlang::with_options(
usethis.quiet = FALSE,
usethis.quiet = getOption("usethis.quiet") %||% FALSE,
usethis::create_project(path)
)
}
3 changes: 3 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ reference:
- title: Other exercises
contents:
- exo_split_changes
- title: All exercises at once
contents:
- create_all_exercises
17 changes: 17 additions & 0 deletions man/create_all_exercises.Rd

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

24 changes: 24 additions & 0 deletions man/saperlipopette-package.Rd

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

20 changes: 20 additions & 0 deletions tests/testthat/_snaps/create-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# create_all_exercises() works

Code
create_all_exercises(parent_path)
Output
+-- committed-to-main
| +-- R
| \-- bla
+-- latest-message
| +-- R
| \-- bla
+-- one-small-change
| +-- R
| \-- bla
\-- split-changes
\-- R
\-- script.R
[1] ""

8 changes: 8 additions & 0 deletions tests/testthat/test-create-all.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("create_all_exercises() works", {
rlang::local_options(cli.default_handler = function(msg) invisible(NULL))
parent_path <- withr::local_tempdir()
expect_snapshot(
create_all_exercises(parent_path),
transform = function(x) gsub(parent_path, "", x, fixed = TRUE)
)
})
1 change: 1 addition & 0 deletions tests/testthat/test-utils-fs.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_that("dir_create() errors if the path exist", {
rlang::local_options(cli.default_handler = function(msg) invisible(NULL))
rlang::local_options(usethis.quiet = FALSE)
parent_path <- withr::local_tempdir()
path <- exo_split_changes(parent_path = parent_path)
expect_error(
Expand Down

0 comments on commit 438e532

Please sign in to comment.