Skip to content

Commit

Permalink
Merge pull request #159 from ropensci/cli
Browse files Browse the repository at this point in the history
Switch from crayon:: to cli::
  • Loading branch information
slager authored Aug 14, 2024
2 parents 7f9473d + fe7de25 commit 37cf803
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BugReports: https://github.com/ropensci/DataPackageR/issues
Depends:
R (>= 3.5.0)
Imports:
crayon,
cli,
desc,
digest,
futile.logger,
Expand All @@ -61,5 +61,5 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
SystemRequirements: pandoc - https://pandoc.org
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export(yml_list_objects)
export(yml_remove_files)
export(yml_remove_objects)
export(yml_write)
importFrom(crayon,bold)
importFrom(crayon,green)
importFrom(desc,desc)
importFrom(futile.logger,INFO)
importFrom(futile.logger,TRACE)
Expand Down
22 changes: 11 additions & 11 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ package_build <- function(packageName = NULL,

.next_steps <- function() {
if (! getOption('DataPackageR_verbose', TRUE)) return(invisible(NULL))
cat(crayon::green(crayon::bold("Next Steps")), "\n") # nolint
cat(crayon::white(crayon::yellow(crayon::bold("1. Update your package documentation.")), "\n")) # nolint
cat(crayon::white(" - Edit the documentation.R file in the package source", crayon::green("data-raw"), "subdirectory and update the roxygen markup."), "\n") # nolint
cat(crayon::white(" - Rebuild the package documentation with ", crayon::red("document()"), "."), "\n") # nolint
cat(crayon::white(crayon::yellow(crayon::bold("2. Add your package to source control.")), "\n")) # nolint
cat(crayon::white(" - Call ", crayon::red("git init ."), " in the package source root directory."), "\n") # nolint
cat(crayon::white(" - ", crayon::red("git add"), " the package files."), "\n") # nolint
cat(crayon::white(" - ", crayon::red("git commit"), " your new package."), "\n") # nolint
cat(crayon::white(" - Set up a github repository for your pacakge."), "\n") # nolint
cat(crayon::white(" - Add the github repository as a remote of your local package repository."), "\n") # nolint
cat(crayon::white(" - ", crayon::red("git push"), " your local repository to gitub."), "\n") # nolint
cat(cli::col_green(cli::style_bold("Next Steps")), "\n") # nolint
cat(cli::col_white(cli::col_yellow(cli::style_bold("1. Update your package documentation.")), "\n")) # nolint
cat(cli::col_white(" - Edit the documentation.R file in the package source", cli::col_green("data-raw"), "subdirectory and update the roxygen markup."), "\n") # nolint
cat(cli::col_white(" - Rebuild the package documentation with ", cli::col_red("document()"), "."), "\n") # nolint
cat(cli::col_white(cli::col_yellow(cli::style_bold("2. Add your package to source control.")), "\n")) # nolint
cat(cli::col_white(" - Call ", cli::col_red("git init ."), " in the package source root directory."), "\n") # nolint
cat(cli::col_white(" - ", cli::col_red("git add"), " the package files."), "\n") # nolint
cat(cli::col_white(" - ", cli::col_red("git commit"), " your new package."), "\n") # nolint
cat(cli::col_white(" - Set up a github repository for your pacakge."), "\n") # nolint
cat(cli::col_white(" - Add the github repository as a remote of your local package repository."), "\n") # nolint
cat(cli::col_white(" - ", cli::col_red("git push"), " your local repository to gitub."), "\n") # nolint
}

#' Check that pkg name inferred from pkg path is same as pkg name in DESCRIPTION
Expand Down
6 changes: 3 additions & 3 deletions R/processData.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ DataPackageR <- function(arg = NULL, deps = TRUE) {
.bullet(
.add_newlines_to_vector(
objects_to_keep[which(objects_to_keep %in% object_names)]),
crayon::red("\u2022")
cli::col_red("\u2022")
)
}
.bullet(
Expand All @@ -171,8 +171,8 @@ DataPackageR <- function(arg = NULL, deps = TRUE) {
),
ifelse(
sum(object_tally) == length(object_tally),
crayon::green("\u2618"),
crayon::green("\u2605")
cli::col_green("\u2618"),
cli::col_green("\u2605")
)
)
if (sum(objects_to_keep %in% object_names) > 0) {
Expand Down
6 changes: 3 additions & 3 deletions R/prompt.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
interactive()
)) {
if (interactive()&interact) {
cat(crayon::cyan("Enter a text description of the changes for the NEWS.md file.\n")) #nocov
cat(cli::col_cyan("Enter a text description of the changes for the NEWS.md file.\n")) #nocov
}else{
if (getOption('DataPackageR_verbose', TRUE)){
cat(crayon::cyan("Non-interactive NEWS.md file update.\n"))
cat(cli::col_cyan("Non-interactive NEWS.md file update.\n"))
}
}
change_description <-
Expand Down Expand Up @@ -85,7 +85,7 @@
.write_changes <- function(string, news_con, what = NULL) {
if (length(string) != 0) {
if (getOption('DataPackageR_verbose', TRUE)){
cat(crayon::cyan(paste0("* ",what,": ",string,"\n")), sep = "")
cat(cli::col_cyan(paste0("* ",what,": ",string,"\n")), sep = "")
}
writeLines(text = paste0("* ",what,": ", string),
con = news_con,
Expand Down
11 changes: 5 additions & 6 deletions R/skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#' @param raw_data_dir \code{character} pointing to a raw data directory. Will be moved with all its subdirectories to "inst/extdata"
#' @param dependencies \code{vector} of \code{character}, paths to R files that will be moved to "data-raw" but not included in the yaml config file. e.g., dependency scripts.
#' @returns No return value, called for side effects
#' @importFrom crayon bold green
#' @examples
#' if(rmarkdown::pandoc_available()){
#' f <- tempdir()
Expand Down Expand Up @@ -87,7 +86,7 @@ datapackage_skeleton <-
description$set_dep("R", "Depends", ">= 3.5.0")
description$set("Roxygen" = "list(markdown = TRUE)")
description$write()
.done(paste0("Added DataVersion string to ", crayon::blue("'DESCRIPTION'")))
.done(paste0("Added DataVersion string to ", cli::col_blue("'DESCRIPTION'")))

usethis::use_directory("data-raw")
usethis::use_directory("data")
Expand Down Expand Up @@ -135,7 +134,7 @@ datapackage_skeleton <-
for (y in x) {
file.copy(y, file.path(package_path, "data-raw"), overwrite = TRUE)
.done(paste0("Copied ", basename(y),
" into ", crayon::blue("'data-raw'")))
" into ", cli::col_blue("'data-raw'")))
}
}
}
Expand All @@ -146,7 +145,7 @@ datapackage_skeleton <-
file.copy(x, file.path(package_path, "inst/extdata"),
recursive = TRUE, overwrite = TRUE
)
.done(paste0("Moved data into ", crayon::blue("'inst/extdata'")))
.done(paste0("Moved data into ", cli::col_blue("'inst/extdata'")))
}
}
.copy_files_to_data_raw(code_files, obj = "code")
Expand All @@ -155,7 +154,7 @@ datapackage_skeleton <-

yml <- construct_yml_config(code = code_files, data = r_object_names)
yaml::write_yaml(yml, file = file.path(package_path, "datapackager.yml"))
.done(paste0("configured ", crayon::blue("'datapackager.yml'"), " file"))
.done(paste0("configured ", cli::col_blue("'datapackager.yml'"), " file"))


oldrdfiles <-
Expand Down Expand Up @@ -184,7 +183,7 @@ datapackage_skeleton <-
}

.done <- function(...) {
.bullet(paste0(...), bullet = crayon::green("\u2714"))
.bullet(paste0(...), bullet = cli::col_green("\u2714"))
}

.bullet <- function(lines, bullet) {
Expand Down
6 changes: 3 additions & 3 deletions R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ use_processing_script <- function(file = NULL, title = NULL, author = NULL, over
#check if the given file or directory already exists
if (utils::file_test("-f",file.path(proj_path,"data-raw",file))|utils::file_test("-d",file.path(proj_path,"data-raw",file))) { #nolint
if (overwrite) {
.bullet(paste0("Courtesy warning: ", basename(file), " exists in ",crayon::blue("'data-raw'"),", and ",crayon::red("WILL")," be overwritten."),bullet = crayon::red("\u2622")) #nolint
.bullet(paste0("Courtesy warning: ", basename(file), " exists in ",cli::col_blue("'data-raw'"),", and ",cli::col_red("WILL")," be overwritten."),bullet = cli::col_red("\u2622")) #nolint
} else {
.bullet(paste0("Courtesy warning: ", basename(file), " exists in ",crayon::blue("'data-raw'"),", and ",crayon::red("WILL NOT")," be overwritten."),bullet = crayon::red("\u2622")) #nolint
.bullet(paste0("Courtesy warning: ", basename(file), " exists in ",cli::col_blue("'data-raw'"),", and ",cli::col_red("WILL NOT")," be overwritten."),bullet = cli::col_red("\u2622")) #nolint
}
}
raw_file <- suppressWarnings(normalizePath(file))
Expand Down Expand Up @@ -137,7 +137,7 @@ use_processing_script <- function(file = NULL, title = NULL, author = NULL, over
# we have a valid file name and should create it.
if (file.exists(file.path(proj_path, "data-raw", basename(raw_file))) &&
!overwrite) {
.bullet(paste0("Skipping file creation: pass overwrite = TRUE to use_processing_script()"), bullet = crayon::red("\u2622")) #nolint
.bullet(paste0("Skipping file creation: pass overwrite = TRUE to use_processing_script()"), bullet = cli::col_red("\u2622")) #nolint
} else {
if (getOption('DataPackageR_verbose', TRUE)){
cat("Attempting to create ", raw_file)
Expand Down

0 comments on commit 37cf803

Please sign in to comment.