diff --git a/R/sepuku.R b/R/sepuku.R index 09f6e9c..a7646b5 100644 --- a/R/sepuku.R +++ b/R/sepuku.R @@ -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 @@ -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 ?") } @@ -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) { diff --git a/R/sepuku_utils.R b/R/sepuku_utils.R index 5e1c6ee..0471641 100644 --- a/R/sepuku_utils.R +++ b/R/sepuku_utils.R @@ -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) diff --git a/dev/flat_sepuku-utils.Rmd b/dev/flat_sepuku-utils.Rmd index b7da640..946f88c 100644 --- a/dev/flat_sepuku-utils.Rmd +++ b/dev/flat_sepuku-utils.Rmd @@ -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) diff --git a/dev/flat_sepuku.Rmd b/dev/flat_sepuku.Rmd index 4443089..c4a197a 100644 --- a/dev/flat_sepuku.Rmd +++ b/dev/flat_sepuku.Rmd @@ -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 ?") } @@ -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) { @@ -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" ) }) @@ -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" ) }) diff --git a/man/sepuku.Rd b/man/sepuku.Rd index 89ec497..127f148 100644 --- a/man/sepuku.Rd +++ b/man/sepuku.Rd @@ -4,12 +4,14 @@ \alias{sepuku} \title{Clean a package from fusen-related files and tags} \usage{ -sepuku(pkg = ".", force = FALSE) +sepuku(pkg = ".", force = FALSE, verbose = FALSE) } \arguments{ \item{pkg}{Character. Path of the current package} \item{force}{logical. whether to force the cleaning or not, without asking if the user is sure about making this operation (default: FALSE)} + +\item{verbose}{logical. whether to display the files that will be deleted or modified (default: FALSE)} } \value{ side effect. A package cleaned from fusen-related files or tags diff --git a/tests/testthat/test-sepuku.R b/tests/testthat/test-sepuku.R index 1de2986..5526c70 100644 --- a/tests/testthat/test-sepuku.R +++ b/tests/testthat/test-sepuku.R @@ -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" ) }) @@ -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" ) })