Skip to content

Commit

Permalink
help refactor - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Nov 10, 2024
1 parent 057d356 commit fcdefa3
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.153.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.411.1`](https://github.com/kamangir/awesome-bash-cli).
built by 🌀 [`blue_options-4.153.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.412.1`](https://github.com/kamangir/awesome-bash-cli).
9 changes: 1 addition & 8 deletions abcli/.abcli/plugins/pypi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ function abcli_pypi() {
local options=$2
local plugin_name=$(abcli_option "$options" plugin abcli)

if [[ "$task" == "help" ]]; then
abcli_pypi_browse "$1,$2"
abcli_pypi_build "$1,$2"
abcli_pypi_install "$1,$2"
return
fi

local function_name=abcli_pypi_$task
if [[ $(type -t $function_name) == "function" ]]; then
$function_name "${@:2}"
return
fi

abcli_log_error "-$plugin_name: pypi: $task: command not found."
abcli_log_error "$plugin_name: pypi: $task: command not found."
return 1
}

Expand Down
11 changes: 0 additions & 11 deletions abcli/.abcli/plugins/pypi/browse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@

function abcli_pypi_browse() {
local options=$1

local plugin_name=$(abcli_option "$options" plugin abcli)

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
local callable=$([[ "$plugin_name" == "abcli" ]] && echo "@" || echo "$plugin_name ")
options="token"
[[ "$plugin_name" == abcli ]] && options="$options$EOP,plugin=<plugin-name>$EOPE"
abcli_show_usage "${callable}pypi browse$ABCUL$options" \
"browse pypi/$plugin_name."
return
fi

local do_token=$(abcli_option_int "$options" token 0)

local module_name=$(abcli_get_module_name_from_plugin $plugin_name)
Expand Down
12 changes: 0 additions & 12 deletions abcli/.abcli/plugins/pypi/build.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
#! /usr/bin/env bash

export abcli_pypi_build_options="browse,install,~rm_dist,~upload"

function abcli_pypi_build() {
local options=$1

local plugin_name=$(abcli_option "$options" plugin abcli)

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
local callable=$([[ "$plugin_name" == "abcli" ]] && echo "@" || echo "$plugin_name ")
options="${EOP}$abcli_pypi_build_options$EOPE"
[[ "$plugin_name" == abcli ]] && options="$options$EOP,plugin=<plugin-name>$EOPE"
abcli_show_usage "${callable}pypi build$ABCUL$options" \
"$plugin_name -> pypi."
return
fi

local do_install=$(abcli_option_int "$options" install 0)
local do_upload=$(abcli_option_int "$options" upload 1)
local do_browse=$(abcli_option_int "$options" browse 0)
Expand Down
8 changes: 0 additions & 8 deletions abcli/.abcli/plugins/pypi/install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#! /usr/bin/env bash

function abcli_pypi_install() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
abcli_show_usage "@pypi install" \
"install pypi."
return
fi

pip3 install --upgrade setuptools wheel twine
python3 -m pip install --upgrade build
}
7 changes: 7 additions & 0 deletions abcli/.abcli/tests/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ function test_abcli_help() {

local module
for module in \
"@pypi" \
"@pypi browse" \
"@pypi build" \
"@pypi install" \
\
"@pytest" \
\
"@batch browse" \
"@batch cat" \
"@batch eval" \
Expand Down
2 changes: 1 addition & 1 deletion abcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

DESCRIPTION = f"{ICON} a language to speak AI."

VERSION = "9.411.1"
VERSION = "9.412.1"

REPO_NAME = "awesome-bash-cli"

Expand Down
60 changes: 33 additions & 27 deletions abcli/help/functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from abcli.help.generic import help_functions as generic_help_functions

from abcli.help.aws_batch import help_functions as help_aws_batch
from abcli.help.browse import help_browse
from abcli.help.cp import help_cp
Expand All @@ -16,6 +18,7 @@
from abcli.help.notebooks import help_functions as help_notebooks
from abcli.help.plugins import help_functions as help_plugins
from abcli.help.open import help_open
from abcli.help.pypi import help_functions as help_pypi
from abcli.help.pytest import help_pytest
from abcli.help.repeat import help_repeat
from abcli.help.sagemaker import help_functions as help_sagemaker
Expand All @@ -24,31 +27,34 @@
from abcli.help.upload import help_upload
from abcli.help.watch import help_watch

help_functions = generic_help_functions(plugin_name="abcli")


help_functions = {
"aws_batch": help_aws_batch,
"browse": help_browse,
"cp": help_cp,
"docker": help_docker,
"download": help_download,
"env": help_env,
"eval": help_eval,
"gif": help_gif,
"git": help_git,
"gpu": help_gpu,
"init": help_init,
"latex": help_latex,
"log": help_log,
"metadata": help_metadata,
"mlflow": help_mlflow,
"notebooks": help_notebooks,
"open": help_open,
"plugins": help_plugins,
"pytest": help_pytest,
"repeat": help_repeat,
"sagemaker": help_sagemaker,
"sleep": help_sleep,
"terraform": help_terraform,
"upload": help_upload,
"watch": help_watch,
}
help_functions.update(
{
"aws_batch": help_aws_batch,
"browse": help_browse,
"cp": help_cp,
"docker": help_docker,
"download": help_download,
"env": help_env,
"eval": help_eval,
"gif": help_gif,
"git": help_git,
"gpu": help_gpu,
"init": help_init,
"latex": help_latex,
"log": help_log,
"metadata": help_metadata,
"mlflow": help_mlflow,
"notebooks": help_notebooks,
"open": help_open,
"plugins": help_plugins,
"repeat": help_repeat,
"sagemaker": help_sagemaker,
"sleep": help_sleep,
"terraform": help_terraform,
"upload": help_upload,
"watch": help_watch,
}
)
6 changes: 4 additions & 2 deletions abcli/help/generic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import List, Dict, Callable, Union

from abcli.help.functions import help_pytest
from abcli.help.pytest import help_pytest
from abcli.help.pypi import help_functions as help_pypi


def generic_help_functions(
def help_functions(
plugin_name: str = "abcli",
) -> Union[Callable, Dict[str, Union[Callable, Dict]]]:
return {
"pypi": help_pypi(plugin_name=plugin_name),
"pytest": lambda tokens, mono: help_pytest(
tokens,
mono=mono,
Expand Down
4 changes: 3 additions & 1 deletion abcli/help/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from blue_options.terminal import show_usage, xtra

from abcli.help.pypi import build_options as pypi_build_options


def help(
tokens: List[str],
Expand Down Expand Up @@ -198,7 +200,7 @@ def help_push(
]
)

build_options = "build,{}".format(os.getenv("abcli_pypi_build_options"))
build_options = f"build,{pypi_build_options}"

return show_usage(
[
Expand Down
85 changes: 85 additions & 0 deletions abcli/help/pypi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from typing import List, Dict, Callable, Union

from blue_options.terminal import show_usage, xtra

build_options = "browse,install,~rm_dist,~upload"


def help_browse(
tokens: List[str],
mono: bool,
plugin_name: str = "abcli",
) -> str:
options = "token"

callable = f"{plugin_name} pypi"

if plugin_name == "abcli":
options = f"plugin=<plugin-name>,{options}"
callable = "@pypi"

return show_usage(
callable.split(" ")
+ [
"browse",
f"[{options}]",
],
f"browse pypi/{plugin_name}.",
mono=mono,
)


def help_build(
tokens: List[str],
mono: bool,
plugin_name: str = "abcli",
) -> str:
options = xtra(build_options, mono=mono)

callable = f"{plugin_name} pypi"

if plugin_name == "abcli":
options = f"{options},plugin=<plugin-name>"
callable = "@pypi"

return show_usage(
callable.split(" ")
+ [
"build",
f"[{options}]",
],
f"build pypi/{plugin_name}.",
mono=mono,
)


def help_install(
tokens: List[str],
mono: bool,
) -> str:
return show_usage(
[
"@pypi",
"install",
],
"install pypi.",
mono=mono,
)


def help_functions(
plugin_name: str = "abcli",
) -> Union[Callable, Dict[str, Union[Callable, Dict]]]:
return {
"browse": lambda tokens, mono: help_browse(
tokens,
mono=mono,
plugin_name=plugin_name,
),
"build": lambda tokens, mono: help_build(
tokens,
mono=mono,
plugin_name=plugin_name,
),
"install": help_install,
}

0 comments on commit fcdefa3

Please sign in to comment.