Display subcommand help with -h/--help

Closes #78
This commit is contained in:
3wc 2021-02-11 15:02:02 +02:00
parent c082645da0
commit 29b22fe162
2 changed files with 52 additions and 35 deletions

View File

@ -20,6 +20,7 @@
- Global `--skip-update|-U` / `--skip-check|-C` options to make things quicker ([37e8b00](https://git.autonomic.zone/coop-cloud/abra/commit/37e8b00))
- `app backup` and `app restore` commands; requires per-app definition ([#70](https://git.autonomic.zone/coop-cloud/abra/issues/70))
- Rename per-type `abra-commands.sh` to `abra.sh`, and include config versions as type-level instead of app-level config ([#43](https://git.autonomic.zone/coop-cloud/abra/issues/43))
- Show per-subcommand help by adding `-h/--help` to a command line ([#38](https://git.autonomic.zone/coop-cloud/abra/issues/78))
# abra 0.4.1 (2020-12-24)

86
abra
View File

@ -38,6 +38,7 @@ Usage:
abra [options] upgrade
abra [options] version
abra [options] help [<subcommands>...]
abra [options]
Options:
-e, --env=<path> Environment variables to load
@ -150,16 +151,16 @@ eval "var_$1+=($value)"; else eval "var_$1=$value"; fi; return 0; fi; done
return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() {
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1783}
usage=${DOC:40:1320}; digest=616a5
shorts=(-C -v -d -s -e -h -U '' '' '' '' '' '' '' '' '' '')
longs=(--skip-check --verbose --debug --stack --env --help --skip-update --status --server --domain --app-name --pass --secrets --all --force --no-tty --user)
argcounts=(0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1); node_0(){ switch __skip_check 0
}; node_1(){ switch __verbose 1; }; node_2(){ switch __debug 2; }; node_3(){
value __stack 3; }; node_4(){ value __env 4; }; node_5(){ switch __help 5; }
node_6(){ switch __skip_update 6; }; node_7(){ switch __status 7; }; node_8(){
value __server 8; }; node_9(){ value __domain 9; }; node_10(){
value __app_name 10; }; node_11(){ switch __pass 11; }; node_12(){
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1800}
usage=${DOC:40:1337}; digest=55732
shorts=(-U -h -e -v -s -C -d '' '' '' '' '' '' '' '' '' '')
longs=(--skip-update --help --env --verbose --stack --skip-check --debug --status --server --domain --app-name --pass --secrets --all --force --no-tty --user)
argcounts=(0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 1); node_0(){ switch __skip_update 0
}; node_1(){ switch __help 1; }; node_2(){ value __env 2; }; node_3(){
switch __verbose 3; }; node_4(){ value __stack 4; }; node_5(){
switch __skip_check 5; }; node_6(){ switch __debug 6; }; node_7(){
switch __status 7; }; node_8(){ value __server 8; }; node_9(){ value __domain 9
}; node_10(){ value __app_name 10; }; node_11(){ switch __pass 11; }; node_12(){
switch __secrets 12; }; node_13(){ switch __all 13; }; node_14(){
switch __force 14; }; node_15(){ switch __no_tty 15; }; node_16(){
value __user 16; }; node_17(){ value _type_ a; }; node_18(){ value _app_ a; }
@ -204,23 +205,24 @@ required 60 33 18 28 102; }; node_104(){ optional 30; }; node_105(){ optional 31
node_108(){ required 60 52 29 45; }; node_109(){ required 60 52 29 54; }
node_110(){ required 60 52 29 55 63; }; node_111(){ required 60 56; }
node_112(){ required 60 57; }; node_113(){ oneormore 32; }; node_114(){
optional 113; }; node_115(){ required 60 58 114; }; node_116(){
either 65 70 73 74 75 76 77 79 80 81 85 87 91 96 97 100 101 103 106 107 108 109 110 111 112 115
}; node_117(){ required 116; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1320}" >&2
exit 1; }'; unset var___skip_check var___verbose var___debug var___stack \
var___env var___help var___skip_update var___status var___server var___domain \
var___app_name var___pass var___secrets var___all var___force var___no_tty \
var___user var__type_ var__app_ var__service_ var__src_ var__dst_ \
optional 113; }; node_115(){ required 60 58 114; }; node_116(){ required 60; }
node_117(){
either 65 70 73 74 75 76 77 79 80 81 85 87 91 96 97 100 101 103 106 107 108 109 110 111 112 115 116
}; node_118(){ required 117; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1337}" >&2
exit 1; }'; unset var___skip_update var___help var___env var___verbose \
var___stack var___skip_check var___debug var___status var___server \
var___domain var___app_name var___pass var___secrets var___all var___force \
var___no_tty var___user var__type_ var__app_ var__service_ var__src_ var__dst_ \
var__backup_file_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \
var__command_ var__host_ var__user_ var__port_ var__subcommands_ var_app \
var_list var_ls var_new var_backup var_deploy var_check var_config var_cp \
var_logs var_ps var_restore var_rm var_delete var_run var_secret var_generate \
var_insert var_undeploy var_server var_add var_init var_apps var_upgrade \
var_version var_help; parse 117 "$@"; local prefix=${DOCOPT_PREFIX:-''}
unset "${prefix}__skip_check" "${prefix}__verbose" "${prefix}__debug" \
"${prefix}__stack" "${prefix}__env" "${prefix}__help" "${prefix}__skip_update" \
"${prefix}__status" "${prefix}__server" "${prefix}__domain" \
var_version var_help; parse 118 "$@"; local prefix=${DOCOPT_PREFIX:-''}
unset "${prefix}__skip_update" "${prefix}__help" "${prefix}__env" \
"${prefix}__verbose" "${prefix}__stack" "${prefix}__skip_check" \
"${prefix}__debug" "${prefix}__status" "${prefix}__server" "${prefix}__domain" \
"${prefix}__app_name" "${prefix}__pass" "${prefix}__secrets" "${prefix}__all" \
"${prefix}__force" "${prefix}__no_tty" "${prefix}__user" "${prefix}_type_" \
"${prefix}_app_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
@ -233,13 +235,13 @@ unset "${prefix}__skip_check" "${prefix}__verbose" "${prefix}__debug" \
"${prefix}delete" "${prefix}run" "${prefix}secret" "${prefix}generate" \
"${prefix}insert" "${prefix}undeploy" "${prefix}server" "${prefix}add" \
"${prefix}init" "${prefix}apps" "${prefix}upgrade" "${prefix}version" \
"${prefix}help"; eval "${prefix}"'__skip_check=${var___skip_check:-false}'
eval "${prefix}"'__verbose=${var___verbose:-false}'
eval "${prefix}"'__debug=${var___debug:-false}'
eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__env=${var___env:-}'
"${prefix}help"; eval "${prefix}"'__skip_update=${var___skip_update:-false}'
eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__skip_update=${var___skip_update:-false}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__verbose=${var___verbose:-false}'
eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__skip_check=${var___skip_check:-false}'
eval "${prefix}"'__debug=${var___debug:-false}'
eval "${prefix}"'__status=${var___status:-false}'
eval "${prefix}"'__server=${var___server:-}'
eval "${prefix}"'__domain=${var___domain:-}'
@ -290,9 +292,9 @@ eval "${prefix}"'upgrade=${var_upgrade:-false}'
eval "${prefix}"'version=${var_version:-false}'
eval "${prefix}"'help=${var_help:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__skip_check" "${prefix}__verbose" "${prefix}__debug" \
"${prefix}__stack" "${prefix}__env" "${prefix}__help" "${prefix}__skip_update" \
"${prefix}__status" "${prefix}__server" "${prefix}__domain" \
declare -p "${prefix}__skip_update" "${prefix}__help" "${prefix}__env" \
"${prefix}__verbose" "${prefix}__stack" "${prefix}__skip_check" \
"${prefix}__debug" "${prefix}__status" "${prefix}__server" "${prefix}__domain" \
"${prefix}__app_name" "${prefix}__pass" "${prefix}__secrets" "${prefix}__all" \
"${prefix}__force" "${prefix}__no_tty" "${prefix}__user" "${prefix}_type_" \
"${prefix}_app_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
@ -777,9 +779,9 @@ sub_app_restore (){
###### .. app deploy
help_app_deploy (){
echo "abra [options] app <domain> deploy [--skip-check]
echo "abra [options] app <app> deploy [--skip-check]
Deploy app <domain> to the configured server.
Deploy app <app> to the configured server.
POWERED BY
docker stack deploy -c compose.yml <app>"
@ -827,7 +829,7 @@ sub_app_deploy (){
)
}
###### .. app <domain> undeploy
###### .. app <app> undeploy
help_app_undeploy (){
echo "abra [options] app <app> undeploy
@ -1464,7 +1466,7 @@ abra() {
abra___server abra___domain abra___force abra___pass \
abra___secrets abra___status abra___no_tty abra___app_name \
abra__subcommands_ abra___skip_update abra___skip_check \
abra__backup_file_ abra___verbose abra___debug
abra__backup_file_ abra___verbose abra___debug abra___help
if ! type tput > /dev/null 2>&1; then
tput() {
@ -1473,6 +1475,7 @@ abra() {
fi
DOCOPT_PREFIX=abra_
DOCOPT_ADD_HELP=false
eval "$(docopt "$@")"
# --stack <stack>
@ -1503,6 +1506,19 @@ abra() {
break
done
if [ "$abra___help" = "true" ]; then
if [ -z "$abra__command_" ]; then
# shellcheck disable=SC2059
printf "$DOC"
exit
elif type "help_${abra__command_}" > /dev/null 2>&1; then
"help_${abra__command_}"
exit
else
error "No help for '$abra__command_'"
fi
fi
# Use abra__command_ in case `command` is provided (i.e. `volume` or `stack`)
CMD="sub_${abra__command_}"
if type "$CMD" > /dev/null 2>&1; then