Skip to content

Commit

Permalink
feat: add messages to create_env and remove_env #15
Browse files Browse the repository at this point in the history
  • Loading branch information
luciorq committed Nov 8, 2024
1 parent 7094100 commit 7471373
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]",
role = c("aut", "cre", "cph"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions R/create_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -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], "[=<>~!].*")
Expand All @@ -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)))
}
}
Expand All @@ -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))
}
16 changes: 16 additions & 0 deletions R/remove_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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))
}

0 comments on commit 7471373

Please sign in to comment.