From 747137389fa4121cc649f84cfba3c24d16c080d8 Mon Sep 17 00:00:00 2001 From: luciorq Date: Fri, 8 Nov 2024 06:11:38 -0500 Subject: [PATCH] feat: add messages to create_env and remove_env #15 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/create_env.R | 20 ++++++++++++++++++-- R/remove_env.R | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8cca511..8c6d045 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: condathis Title: Run Any CLI Tool on a Conda Environment -Version: 0.0.6.9006 +Version: 0.0.6.9007 Authors@R: c( person("Lucio", "Queiroz", , "luciorqueiroz@gmail.com", role = c("aut", "cre", "cph"), diff --git a/NEWS.md b/NEWS.md index d4ca2b6..bd48191 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,8 @@ * Internal `micromamba` version bump to "2.0.2-2". +* `create_env()` and `remove_env()` have improved output. + # condathis 0.0.6 ## Breaking changes diff --git a/R/create_env.R b/R/create_env.R index 008466d..871aad4 100644 --- a/R/create_env.R +++ b/R/create_env.R @@ -108,8 +108,10 @@ create_env <- function( if (isTRUE(method_to_use %in% c("native", "auto"))) { if (env_exists(env_name = env_name) && isFALSE(overwrite)) { - pkg_list_res <- list_packages(env_name = env_name, verbose = verbose) - + pkg_list_res <- list_packages( + env_name = env_name, + verbose = "silent" + ) pkg_present_vector <- vector(mode = "logical", length = length(packages)) for (i in seq_along(packages)) { pkg_name_str <- stringr::str_remove(packages[i], "[=<>~!].*") @@ -125,6 +127,13 @@ create_env <- function( } if (isTRUE(all(pkg_present_vector))) { + if (isTRUE(verbose %in% c("full", "output"))) { + cli::cli_inform( + message = c( + `!` = "Environment {.field {env_name}} already exists." + ) + ) + } return(invisible(list(status = 0L, stdout = "", stderr = "", timeout = FALSE))) } } @@ -146,5 +155,12 @@ create_env <- function( error = "cancel" ) } + if (isTRUE(verbose %in% c("full", "output"))) { + cli::cli_inform( + message = c( + `!` = "Environment {.field {env_name}} succesfully created." + ) + ) + } return(invisible(px_res)) } diff --git a/R/remove_env.R b/R/remove_env.R index 71bd189..6cff142 100644 --- a/R/remove_env.R +++ b/R/remove_env.R @@ -7,6 +7,15 @@ #' @export remove_env <- function(env_name = "condathis-env", verbose = "silent") { + if (isFALSE(env_exists(env_name))) { + cli::cli_abort( + message = c( + `x` = "Environment {.field {env_name}} do not exist.", + `!` = "Check {.code list_envs()} for available environments." + ), + class = "condathis_error_env_remove" + ) + } px_res <- native_cmd( conda_cmd = "env", conda_args = c( @@ -18,5 +27,12 @@ remove_env <- function(env_name = "condathis-env", ), verbose = verbose ) + if (isTRUE(verbose %in% c("full", "output"))) { + cli::cli_inform( + message = c( + `!` = "Environment {.field {env_name}} succesfully removed." + ) + ) + } return(invisible(px_res)) }