diff --git a/README.md b/README.md index ebfe910b..dc027e6b 100644 --- a/README.md +++ b/README.md @@ -63,4 +63,4 @@ create a copy of [`sample.env`](./abcli/sample.env) as `.env` and fill in the se [![pylint](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/awesome-bash-cli/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/awesome-bash-cli/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/abcli.svg)](https://pypi.org/project/abcli/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/abcli)](https://pypistats.org/packages/abcli) -built by 🌀 [`blue_options-4.177.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.458.1`](https://github.com/kamangir/awesome-bash-cli). +built by 🌀 [`blue_options-4.180.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.460.1`](https://github.com/kamangir/awesome-bash-cli). diff --git a/abcli/.abcli/plugins/conda.sh b/abcli/.abcli/plugins/conda.sh index ab714da6..a131c55c 100644 --- a/abcli/.abcli/plugins/conda.sh +++ b/abcli/.abcli/plugins/conda.sh @@ -3,69 +3,6 @@ function abcli_conda() { local task=$(abcli_unpack_keyword $1) - if [ "$task" == "help" ]; then - abcli_conda create "$@" - abcli_conda exists "$@" - abcli_conda list "$@" - abcli_conda remove "$@" - return - fi - - if [[ "$2" == "help" ]]; then - local options - case $task in - create) - options="${EOP}clone=,~install_plugin,${EOPE}name=${EOP},repo=,~recreate${EOP}" - abcli_show_usage "@conda create$ABCUL$options" \ - "create conda environment." - ;; - exists) - abcli_show_usage "@conda exists$ABCUL[]" \ - "does conda environment exist? true|false." - ;; - list) - abcli_show_usage "@conda list" \ - "show list of conda environments." - ;; - remove | rm) - abcli_show_usage "@conda remove|rm$ABCUL[]" \ - "remove conda environment." - ;; - *) - abcli_log_error "@conda: $task: command not found." - return 1 - ;; - esac - - return - fi - - if [[ ",remove,rm," == *",$task,"* ]]; then - local environment_name=$(abcli_clarify_input $2 abcli) - - conda activate base - conda remove -y --name $environment_name --all - - return - fi - - if [ "$task" == "exists" ]; then - local environment_name=$(abcli_clarify_input $2 abcli) - - if conda info --envs | grep -q "^$environment_name "; then - echo 1 - else - echo 0 - fi - - return - fi - - if [ "$task" == "list" ]; then - conda info --envs "${@:2}" - return - fi - local function_name="abcli_conda_$task" if [[ $(type -t $function_name) == "function" ]]; then $function_name "${@:2}" diff --git a/abcli/.abcli/plugins/conda/exists.sh b/abcli/.abcli/plugins/conda/exists.sh new file mode 100644 index 00000000..eb400d3d --- /dev/null +++ b/abcli/.abcli/plugins/conda/exists.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env bash + +function abcli_conda_exists() { + local options=$1 + local environment_name=$(abcli_option "$options" name abcli) + + if conda info --envs | grep -q "^$environment_name "; then + echo 1 + else + echo 0 + fi +} diff --git a/abcli/.abcli/plugins/conda/list.sh b/abcli/.abcli/plugins/conda/list.sh new file mode 100644 index 00000000..d347f7cd --- /dev/null +++ b/abcli/.abcli/plugins/conda/list.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +function abcli_conda_list() { + abcli_eval ,$1 \ + conda info \ + --envs "${@:2}" +} diff --git a/abcli/.abcli/plugins/conda/rm.sh b/abcli/.abcli/plugins/conda/rm.sh new file mode 100644 index 00000000..6c87a7e9 --- /dev/null +++ b/abcli/.abcli/plugins/conda/rm.sh @@ -0,0 +1,20 @@ +#! /usr/bin/env bash + +function abcli_conda_rm() { + local options=$1 + local environment_name=$(abcli_option "$options" name abcli) + + local exists=$(abcli_conda_exists $environment_name) + if [[ "$exists" == 0 ]]; then + abcli_log_warning "@conda: $environment_name does not exist." + return 0 + fi + + conda activate base + [[ $? -ne 0 ]] && return 1 + + abcli_eval ,$options \ + conda remove -y \ + --name $environment_name \ + --all +} diff --git a/abcli/.abcli/tests/help.sh b/abcli/.abcli/tests/help.sh index ca63055e..b2c49e07 100644 --- a/abcli/.abcli/tests/help.sh +++ b/abcli/.abcli/tests/help.sh @@ -19,6 +19,12 @@ function test_abcli_help() { \ "@cat" \ \ + "@conda" \ + "@conda create" \ + "@conda exists" \ + "@conda list" \ + "@conda rm" \ + \ "@docker browse " \ "@docker build " \ "@docker clear " \ diff --git a/abcli/__init__.py b/abcli/__init__.py index fe5efb4b..9c1df5a3 100644 --- a/abcli/__init__.py +++ b/abcli/__init__.py @@ -6,7 +6,7 @@ DESCRIPTION = f"{ICON} A language to speak AI." -VERSION = "9.458.1" +VERSION = "9.460.1" REPO_NAME = "awesome-bash-cli" diff --git a/abcli/help/conda.py b/abcli/help/conda.py new file mode 100644 index 00000000..fde0104f --- /dev/null +++ b/abcli/help/conda.py @@ -0,0 +1,90 @@ +from typing import List + +from blue_options.terminal import show_usage, xtra + + +def help_create( + tokens: List[str], + mono: bool, +) -> str: + options = "".join( + [ + xtra("clone=,~install_plugin,", mono=mono), + "name=", + xtra(",repo=,~recreate", mono=mono), + ] + ) + + return show_usage( + [ + "@conda", + "create", + f"[{options}]", + ], + "create conda environment.", + mono=mono, + ) + + +def help_exists( + tokens: List[str], + mono: bool, +) -> str: + options = "name=" + + return show_usage( + [ + "@conda", + "exists", + f"[{options}]", + ], + "does conda environment exist?", + mono=mono, + ) + + +def help_list( + tokens: List[str], + mono: bool, +) -> str: + options = xtra("dryrun", mono=mono) + + return show_usage( + [ + "@conda", + "list", + f"[{options}]", + ], + "show list of conda environments.", + mono=mono, + ) + + +def help_rm( + tokens: List[str], + mono: bool, +) -> str: + options = "".join( + [ + xtra("dryrun,", mono=mono), + "name=", + ] + ) + + return show_usage( + [ + "@conda", + "rm", + f"[{options}]", + ], + "rm conda environment.", + mono=mono, + ) + + +help_functions = { + "create": help_create, + "exists": help_exists, + "list": help_list, + "rm": help_rm, +} diff --git a/abcli/help/functions.py b/abcli/help/functions.py index 5047a4b7..2f4e384a 100644 --- a/abcli/help/functions.py +++ b/abcli/help/functions.py @@ -3,6 +3,7 @@ from abcli.help.aws_batch import help_functions as help_aws_batch from abcli.help.blueness import help_blueness from abcli.help.browse import help_browse +from abcli.help.conda import help_functions as help_conda from abcli.help.cp import help_cp from abcli.help.docker import help_functions as help_docker from abcli.help.download import help_download @@ -50,6 +51,7 @@ "blueness": help_blueness, "browse": help_browse, "cat": help_cat, + "conda": help_conda, "cp": help_cp, "docker": help_docker, "download": help_download,