Finally work out subcommands
This commit is contained in:
parent
44c41830a7
commit
a13e58c6c0
96
abra
96
abra
@ -2,11 +2,11 @@
|
||||
|
||||
###### Global help
|
||||
|
||||
DOC="The cooperative cloud utility belt 🎩🐇
|
||||
DOC="
|
||||
The cooperative cloud utility belt 🎩🐇
|
||||
|
||||
Usage:
|
||||
abra [--config=<path>] [--env=<path>] [--help]
|
||||
[--stack=<path>] [--version] <command> [<args>]
|
||||
Usage: abra [-c|--config=<path>] [-e|--env=<path>] [-h|--help]
|
||||
[-s|--stack=<path>] [-v|--version] <command> [<args>...]
|
||||
|
||||
Options:
|
||||
-c, --config=<path> Stack configuration to use
|
||||
@ -17,19 +17,33 @@ Options:
|
||||
|
||||
These are common Abra commands used in various situations:
|
||||
|
||||
server manage remote host
|
||||
cp copy files to a container
|
||||
Manage an application lifecycle:
|
||||
deploy let 'em rip
|
||||
logs tail logs from a deployed service
|
||||
multilogs tail logs from a whole stack
|
||||
run run a command in the specified service's container
|
||||
secret manage secrets
|
||||
upgrade upgrade to the latest version
|
||||
|
||||
See 'abra help <command>' to read about a specific subcommand."
|
||||
View logs from running applications:
|
||||
logs tail logs from a deployed service
|
||||
multilogs tail logs from a whole stack
|
||||
|
||||
Interact with running containers:
|
||||
cp copy files to a container
|
||||
run run a command in the specified service's container
|
||||
|
||||
Manage servers:
|
||||
server add <host> [user] [port] add docker context
|
||||
server rm <host> remove docker context
|
||||
server use <host> activate docker context
|
||||
server init <host> activate docker swarm mode
|
||||
|
||||
Manage secrets:
|
||||
secret generate <secret> <version> [pwgen] generate & store secret
|
||||
secret insert <secret> <version> <password> save password in docker & pass
|
||||
|
||||
See 'abra help <command>' to read about a specific subcommand.
|
||||
"
|
||||
|
||||
# docopt parser below, refresh this parser with `docopt.sh abra`
|
||||
# shellcheck disable=2016,1075
|
||||
# shellcheck disable=2016,1075,2154
|
||||
docopt() { parse() { if ${DOCOPT_DOC_CHECK:-true}; then local doc_hash
|
||||
if doc_hash=$(printf "%s" "$DOC" | (sha256sum 2>/dev/null || shasum -a 256)); then
|
||||
if [[ ${doc_hash:0:5} != "$digest" ]]; then
|
||||
@ -95,8 +109,18 @@ local node_idx; ((testdepth++)) || true; for node_idx in "$@"; do
|
||||
if ! "node_$node_idx"; then left=("${initial_left[@]}"); ((testdepth--)) || true
|
||||
return 1; fi; done; if [[ $((--testdepth)) -eq 0 ]]; then
|
||||
left=("${initial_left[@]}"); for node_idx in "$@"; do "node_$node_idx"; done; fi
|
||||
return 0; }; optional() { local node_idx; for node_idx in "$@"; do
|
||||
"node_$node_idx"; done; return 0; }; switch() { local i
|
||||
return 0; }; either() { local initial_left=("${left[@]}"); local best_match_idx
|
||||
local match_count; local node_idx; ((testdepth++)) || true
|
||||
for node_idx in "$@"; do if "node_$node_idx"; then
|
||||
if [[ -z $match_count || ${#left[@]} -lt $match_count ]]; then
|
||||
best_match_idx=$node_idx; match_count=${#left[@]}; fi; fi
|
||||
left=("${initial_left[@]}"); done; ((testdepth--)) || true
|
||||
if [[ -n $best_match_idx ]]; then "node_$best_match_idx"; return 0; fi
|
||||
left=("${initial_left[@]}"); return 1; }; optional() { local node_idx
|
||||
for node_idx in "$@"; do "node_$node_idx"; done; return 0; }; oneormore() {
|
||||
local i=0; local prev=${#left[@]}; while "node_$1"; do ((i++)) || true
|
||||
[[ $prev -eq ${#left[@]} ]] && break; prev=${#left[@]}; done
|
||||
if [[ $i -ge 1 ]]; then return 0; fi; return 1; }; switch() { local i
|
||||
for i in "${!left[@]}"; do local l=${left[$i]}
|
||||
if [[ ${parsed_params[$l]} = "$2" ]]; then
|
||||
left=("${left[@]:0:$i}" "${left[@]:((i+1))}")
|
||||
@ -111,31 +135,37 @@ 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:0:857}
|
||||
usage=${DOC:39:110}; digest=29484; shorts=(-c -e -h -s -v)
|
||||
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1345}
|
||||
usage=${DOC:40:131}; digest=f2937; shorts=(-c -e -h -s -v)
|
||||
longs=(--config --env --help --stack --version); argcounts=(1 1 0 1 0)
|
||||
node_0(){ value __config 0; }; node_1(){ value __env 1; }; node_2(){
|
||||
switch __help 2; }; node_3(){ value __stack 3; }; node_4(){ switch __version 4
|
||||
}; node_5(){ value _command_ a; }; node_6(){ value _args_ a; }; node_7(){
|
||||
optional 0; }; node_8(){ optional 1; }; node_9(){ optional 2; }; node_10(){
|
||||
optional 3; }; node_11(){ optional 4; }; node_12(){ optional 6; }; node_13(){
|
||||
required 7 8 9 10 11 5 12; }; node_14(){ required 13; }
|
||||
cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2
|
||||
printf "%s\n" "${DOC:39:110}" >&2; exit 1; }'; unset var___config var___env \
|
||||
var___help var___stack var___version var__command_ var__args_; parse 14 "$@"
|
||||
node_0(){ value __config 0 true; }; node_1(){ value __env 1 true; }; node_2(){
|
||||
switch __help 2; }; node_3(){ value __stack 3 true; }; node_4(){
|
||||
switch __version 4; }; node_5(){ value _command_ a; }; node_6(){
|
||||
value _args_ a true; }; node_7(){ optional 0 0; }; node_8(){ optional 1 1; }
|
||||
node_9(){ either 2 2; }; node_10(){ optional 9; }; node_11(){ optional 3 3; }
|
||||
node_12(){ either 4 4; }; node_13(){ optional 12; }; node_14(){ oneormore 6; }
|
||||
node_15(){ optional 14; }; node_16(){ required 7 8 10 11 13 5 15; }; node_17(){
|
||||
required 16; }; cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2
|
||||
printf "%s\n" "${DOC:40:131}" >&2; exit 1; }'; unset var___config var___env \
|
||||
var___help var___stack var___version var__command_ var__args_; parse 17 "$@"
|
||||
local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__config" "${prefix}__env" \
|
||||
"${prefix}__help" "${prefix}__stack" "${prefix}__version" "${prefix}_command_" \
|
||||
"${prefix}_args_"; eval "${prefix}"'__config=${var___config:-}'
|
||||
eval "${prefix}"'__env=${var___env:-}'
|
||||
"${prefix}_args_"; if declare -p var___config >/dev/null 2>&1; then
|
||||
eval "${prefix}"'__config=("${var___config[@]}")'; else
|
||||
eval "${prefix}"'__config=()'; fi; if declare -p var___env >/dev/null 2>&1; then
|
||||
eval "${prefix}"'__env=("${var___env[@]}")'; else eval "${prefix}"'__env=()'; fi
|
||||
eval "${prefix}"'__help=${var___help:-false}'
|
||||
eval "${prefix}"'__stack=${var___stack:-}'
|
||||
if declare -p var___stack >/dev/null 2>&1; then
|
||||
eval "${prefix}"'__stack=("${var___stack[@]}")'; else
|
||||
eval "${prefix}"'__stack=()'; fi
|
||||
eval "${prefix}"'__version=${var___version:-false}'
|
||||
eval "${prefix}"'_command_=${var__command_:-}'
|
||||
eval "${prefix}"'_args_=${var__args_:-}'; local docopt_i=1
|
||||
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
|
||||
declare -p "${prefix}__config" "${prefix}__env" "${prefix}__help" \
|
||||
"${prefix}__stack" "${prefix}__version" "${prefix}_command_" "${prefix}_args_"
|
||||
done; }
|
||||
if declare -p var__args_ >/dev/null 2>&1; then
|
||||
eval "${prefix}"'_args_=("${var__args_[@]}")'; else eval "${prefix}"'_args_=()'
|
||||
fi; local docopt_i=1; [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2
|
||||
for ((;docopt_i>0;docopt_i--)); do declare -p "${prefix}__config" \
|
||||
"${prefix}__env" "${prefix}__help" "${prefix}__stack" "${prefix}__version" \
|
||||
"${prefix}_command_" "${prefix}_args_"; done; }
|
||||
# docopt parser above, complete command for generating this parser is `docopt.sh abra`
|
||||
|
||||
PROGRAM_NAME=$(basename "$0")
|
||||
|
Loading…
Reference in New Issue
Block a user