Skip to content
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

feat: Add verbose option in sepuku #264

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions R/sepuku.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @param pkg Character. Path of the current package
#' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE)
#' @param verbose logical. whether to display the files that will be deleted or modified (default: FALSE)
#' @return side effect. A package cleaned from fusen-related files or tags
#' @importFrom cli cli_alert_info cli_alert_danger cli_abort cli_alert_success
#' @export
Expand Down Expand Up @@ -112,7 +113,8 @@
#' }
sepuku <- function(
pkg = ".",
force = FALSE) {
force = FALSE,
verbose = FALSE) {
if (!dir.exists(file.path(pkg, "dev"))) {
cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?")
}
Expand All @@ -130,24 +132,28 @@ sepuku <- function(
if (length(flat_files) == 0) {
cli_alert_info("No flat files were detected.")
} else {
cli_alert_info(
paste0(
"The following flat files were detected and will therefore be deleted from your package:\n",
paste0(flat_files, collapse = "\n")
if (verbose) {
cli_alert_info(
paste0(
"The following flat files were detected and will therefore be deleted from your package:\n",
paste0(flat_files, collapse = "\n")
)
)
)
}
}

files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg)
if (length(files_to_be_modified) == 0) {
cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.")
} else {
cli_alert_info(
paste0(
"The following files have been identified as containing fusen-related tags and will therefore be modified:\n",
paste0(files_to_be_modified, collapse = "\n")
if (verbose) {
cli_alert_info(
paste0(
"The following files have been identified as containing fusen-related tags and will therefore be modified:\n",
paste0(files_to_be_modified, collapse = "\n")
)
)
)
}
}

if (length(flat_files) == 0 && length(files_to_be_modified) == 0) {
Expand Down
7 changes: 6 additions & 1 deletion R/sepuku_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ find_files_with_fusen_tags <- function(pkg = ".") {
function(file) {
if (
length(
grep(paste(fusen_tags, collapse = "|"), tolower(readLines(file)))
grep(
paste(fusen_tags, collapse = "|"),
tolower(
suppressWarnings(readLines(file))
)
)
) > 0
) {
return(file)
Expand Down
7 changes: 6 additions & 1 deletion dev/flat_sepuku-utils.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ find_files_with_fusen_tags <- function(pkg = ".") {
function(file) {
if (
length(
grep(paste(fusen_tags, collapse = "|"), tolower(readLines(file)))
grep(
paste(fusen_tags, collapse = "|"),
tolower(
suppressWarnings(readLines(file))
)
)
) > 0
) {
return(file)
Expand Down
32 changes: 19 additions & 13 deletions dev/flat_sepuku.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ Please be aware that this operation is irreversible. You will lose all the histo
#'
#' @param pkg Character. Path of the current package
#' @param force logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE)
#' @param verbose logical. whether to display the files that will be deleted or modified (default: FALSE)
#' @return side effect. A package cleaned from fusen-related files or tags
#' @importFrom cli cli_alert_info cli_alert_danger cli_abort cli_alert_success
#' @export
sepuku <- function(
pkg = ".",
force = FALSE) {
force = FALSE,
verbose = FALSE) {
if (!dir.exists(file.path(pkg, "dev"))) {
cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?")
}
Expand All @@ -53,24 +55,28 @@ sepuku <- function(
if (length(flat_files) == 0) {
cli_alert_info("No flat files were detected.")
} else {
cli_alert_info(
paste0(
"The following flat files were detected and will therefore be deleted from your package:\n",
paste0(flat_files, collapse = "\n")
if (verbose) {
cli_alert_info(
paste0(
"The following flat files were detected and will therefore be deleted from your package:\n",
paste0(flat_files, collapse = "\n")
)
)
)
}
}

files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg)
if (length(files_to_be_modified) == 0) {
cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.")
} else {
cli_alert_info(
paste0(
"The following files have been identified as containing fusen-related tags and will therefore be modified:\n",
paste0(files_to_be_modified, collapse = "\n")
if (verbose) {
cli_alert_info(
paste0(
"The following files have been identified as containing fusen-related tags and will therefore be modified:\n",
paste0(files_to_be_modified, collapse = "\n")
)
)
)
}
}

if (length(flat_files) == 0 && length(files_to_be_modified) == 0) {
Expand Down Expand Up @@ -337,7 +343,7 @@ usethis::with_project(dummypackage, {
)

expect_message(
sepuku(force = TRUE),
sepuku(force = TRUE, verbose = TRUE),
"The following flat files were detected and will therefore be deleted from your package:\ndev/flat_flat1.Rmd\ndev/flat_qmd.qmd\ndev/flat_history/flat_old.Rmd\ndev/flat_history/flat_old.qmd"
)
})
Expand Down Expand Up @@ -400,7 +406,7 @@ usethis::with_project(dummypackage, {
)

expect_message(
sepuku(force = TRUE),
sepuku(force = TRUE, verbose = TRUE),
"The following files have been identified as containing fusen-related tags and will therefore be modified:\nR/flat1_rmd.R\nR/flat2_rmd.R\ntests/testthat/test-flat1_rmd.R\ntests/testthat/test-flat2_rmd.R\nvignettes/get-started-2.Rmd\nvignettes/get-started.Rmd"
)
})
Expand Down
4 changes: 3 additions & 1 deletion man/sepuku.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-sepuku.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ usethis::with_project(dummypackage, {
)

expect_message(
sepuku(force = TRUE),
sepuku(force = TRUE, verbose = TRUE),
"The following flat files were detected and will therefore be deleted from your package:\ndev/flat_flat1.Rmd\ndev/flat_qmd.qmd\ndev/flat_history/flat_old.Rmd\ndev/flat_history/flat_old.qmd"
)
})
Expand Down Expand Up @@ -158,7 +158,7 @@ usethis::with_project(dummypackage, {
)

expect_message(
sepuku(force = TRUE),
sepuku(force = TRUE, verbose = TRUE),
"The following files have been identified as containing fusen-related tags and will therefore be modified:\nR/flat1_rmd.R\nR/flat2_rmd.R\ntests/testthat/test-flat1_rmd.R\ntests/testthat/test-flat2_rmd.R\nvignettes/get-started-2.Rmd\nvignettes/get-started.Rmd"
)
})
Expand Down
Loading