-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc to be made one test failing in non interactive #257
- Loading branch information
Showing
6 changed files
with
538 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# WARNING - Generated by {fusen} from dev/flat_sepuku.Rmd: do not edit by hand | ||
|
||
#' sepuku Title | ||
#' | ||
#' @return 1 | ||
#' @export | ||
#' | ||
#' @examples | ||
#' sepuku() | ||
sepuku <- function( | ||
pkg = ".", | ||
force = FALSE) { | ||
if (!dir.exists(file.path(pkg, "dev"))) { | ||
cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?") | ||
} | ||
|
||
config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml") | ||
|
||
if (!file.exists(config_file)) { | ||
cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.") | ||
} else { | ||
cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.") | ||
} | ||
|
||
flat_files <- list_flat_files(pkg = pkg) | ||
|
||
if (length(flat_files) == 0) { | ||
cli::cli_alert_info("No flat files were detected.") | ||
} else { | ||
cli::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::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.") | ||
} else { | ||
cli::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) { | ||
return(invisible(NULL)) | ||
} | ||
|
||
do_it <- force | ||
|
||
if (!force) { | ||
cli::cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.") | ||
sure <- paste( | ||
"\nAre you sure of what you are doing? (y/n)\n" | ||
) | ||
clean <- readline(sure) == "y" || readline(sure) == "yes" | ||
if (isTRUE(clean) || clean == "yes") { | ||
do_it <- TRUE | ||
} else if (isFALSE(clean) || clean == "no") { | ||
do_it <- FALSE | ||
} else { | ||
stop("clean should be TRUE, FALSE, 'yes'or 'no'") | ||
} | ||
} | ||
|
||
if (isTRUE(do_it)) { | ||
if (length(flat_files) > 0) { | ||
invisible( | ||
lapply( | ||
flat_files, | ||
function(f) { | ||
file.remove(file.path(pkg, f)) | ||
} | ||
) | ||
) | ||
} | ||
|
||
if (length(files_to_be_modified) > 0) { | ||
invisible( | ||
lapply( | ||
files_to_be_modified, | ||
function(f) { | ||
clean_fusen_tags_in_files(pkg = pkg, files_to_clean = f) | ||
} | ||
) | ||
) | ||
} | ||
if (file.exists(config_file)) { | ||
file.remove(config_file) | ||
} | ||
} | ||
|
||
cli::cli_alert_info("Cleaning is done !") | ||
|
||
return(invisible(TRUE)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.