From 810ff45a11435d17a022c340bf0db27be19d987c Mon Sep 17 00:00:00 2001 From: kamangir Date: Tue, 5 Nov 2024 18:44:53 -0800 Subject: [PATCH] release + help refactor - kamangir/bolt#746 --- README.md | 2 +- abcli/.abcli/plugins/repeat.sh | 20 -------------------- abcli/.abcli/tests/eval.sh | 9 +++++++++ abcli/.abcli/tests/help.sh | 6 ++++-- abcli/.abcli/tests/repeat.sh | 9 +++++++++ abcli/__init__.py | 2 +- abcli/help/eval.py | 25 +++++++++++++++++++++++++ abcli/help/functions.py | 4 ++++ abcli/help/repeat.py | 27 +++++++++++++++++++++++++++ abcli/help/watch.py | 9 +++++++-- 10 files changed, 87 insertions(+), 26 deletions(-) delete mode 100644 abcli/.abcli/plugins/repeat.sh create mode 100644 abcli/.abcli/tests/eval.sh create mode 100644 abcli/.abcli/tests/repeat.sh create mode 100644 abcli/help/eval.py create mode 100644 abcli/help/repeat.py diff --git a/README.md b/README.md index 83809aaf..44b2ae61 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.149.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.403.1`](https://github.com/kamangir/awesome-bash-cli). +built by 🌀 [`blue_options-4.150.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.404.1`](https://github.com/kamangir/awesome-bash-cli). diff --git a/abcli/.abcli/plugins/repeat.sh b/abcli/.abcli/plugins/repeat.sh deleted file mode 100644 index 92551172..00000000 --- a/abcli/.abcli/plugins/repeat.sh +++ /dev/null @@ -1,20 +0,0 @@ -#! /usr/bin/env bash - -function abcli_repeat() { - local task=$(abcli_unpack_keyword $1 help) - - if [ "$task" == "help" ] ; then - abcli_show_usage "abcli repeat " \ - "repeat times." - return - fi - - local count=$1 - local command=${@:2} - - # https://stackoverflow.com/a/3737773/17619982 - for index in $(seq $count); do - abcli_log "$index/$count: $command" - $command - done -} \ No newline at end of file diff --git a/abcli/.abcli/tests/eval.sh b/abcli/.abcli/tests/eval.sh new file mode 100644 index 00000000..a26c2696 --- /dev/null +++ b/abcli/.abcli/tests/eval.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env bash + +function test_abcli_eval() { + abcli_eval - ls + abcli_assert "$?" 0 + + abcli_eval - lsz + abcli_assert "$?" 0 not +} diff --git a/abcli/.abcli/tests/help.sh b/abcli/.abcli/tests/help.sh index e294e744..3996bb95 100644 --- a/abcli/.abcli/tests/help.sh +++ b/abcli/.abcli/tests/help.sh @@ -53,14 +53,16 @@ function test_abcli_help() { "@plugins list_of_installed" \ "@plugins transform" \ \ - "abcli_sleep" \ + "@repeat" \ + \ + "@sleep" \ \ "@terraform" \ "@terraform cat" \ "@terraform disable" \ "@terraform enable" \ \ - "abcli_watch" \ + "@watch" \ \ "abcli"; do abcli_eval ,$options \ diff --git a/abcli/.abcli/tests/repeat.sh b/abcli/.abcli/tests/repeat.sh new file mode 100644 index 00000000..9fb04f50 --- /dev/null +++ b/abcli/.abcli/tests/repeat.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env bash + +function test_abcli_repeat() { + abcli_repeat - ls + abcli_assert "$?" 0 + + abcli_repeat count=3 ls + abcli_assert "$?" 0 +} diff --git a/abcli/__init__.py b/abcli/__init__.py index 5a57973c..cf21d57e 100644 --- a/abcli/__init__.py +++ b/abcli/__init__.py @@ -6,7 +6,7 @@ DESCRIPTION = f"{ICON} a language to speak AI." -VERSION = "9.403.1" +VERSION = "9.404.1" REPO_NAME = "awesome-bash-cli" diff --git a/abcli/help/eval.py b/abcli/help/eval.py new file mode 100644 index 00000000..5dd140be --- /dev/null +++ b/abcli/help/eval.py @@ -0,0 +1,25 @@ +from typing import List + +from blue_options.terminal import show_usage, xtra + + +def options(mono: bool): + return xtra( + "dryrun,~log,path=", + mono=mono, + ) + + +def help_eval( + tokens: List[str], + mono: bool, +) -> str: + return show_usage( + [ + "@eval", + f"[{options(mono=mono)}]", + "", + ], + "eval .", + mono=mono, + ) diff --git a/abcli/help/functions.py b/abcli/help/functions.py index 9aa213be..6b5a07e1 100644 --- a/abcli/help/functions.py +++ b/abcli/help/functions.py @@ -2,6 +2,7 @@ from abcli.help.cp import help_cp from abcli.help.docker import help_functions as help_docker from abcli.help.download import help_download +from abcli.help.eval import help_eval from abcli.help.gif import help_gif from abcli.help.git import help_functions as help_git from abcli.help.gpu import help_functions as help_gpu @@ -13,6 +14,7 @@ from abcli.help.notebooks import help_functions as help_notebooks from abcli.help.plugins import help_functions as help_plugins from abcli.help.pytest import help_pytest +from abcli.help.repeat import help_repeat from abcli.help.sagemaker import help_functions as help_sagemaker from abcli.help.sleep import help_sleep from abcli.help.terraform import help_functions as help_terraform @@ -24,6 +26,7 @@ "cp": help_cp, "docker": help_docker, "download": help_download, + "eval": help_eval, "gif": help_gif, "git": help_git, "gpu": help_gpu, @@ -35,6 +38,7 @@ "notebooks": help_notebooks, "plugins": help_plugins, "pytest": help_pytest, + "repeat": help_repeat, "sagemaker": help_sagemaker, "sleep": help_sleep, "terraform": help_terraform, diff --git a/abcli/help/repeat.py b/abcli/help/repeat.py new file mode 100644 index 00000000..d8ada433 --- /dev/null +++ b/abcli/help/repeat.py @@ -0,0 +1,27 @@ +from typing import List + +from blue_options.terminal import show_usage + +from abcli.help.eval import options as eval_options + + +def help_repeat( + tokens: List[str], + mono: bool, +) -> str: + options = "".join( + [ + "count=,", + eval_options(mono=mono), + ] + ) + + return show_usage( + [ + "@repeat", + f"[{options}]", + "", + ], + "repeat .", + mono=mono, + ) diff --git a/abcli/help/watch.py b/abcli/help/watch.py index a7a47d00..d442f443 100644 --- a/abcli/help/watch.py +++ b/abcli/help/watch.py @@ -1,13 +1,18 @@ from typing import List -from blue_options.terminal import show_usage +from blue_options.terminal import show_usage, xtra def help_watch( tokens: List[str], mono: bool, ) -> str: - options = "~clear,dryrun,seconds=" + options = "".join( + [ + xtra("~clear,dryrun,", mono=mono), + "seconds=", + ] + ) return show_usage( [