Add --server filter to app list..

.. and add `server <host> apps` as an alias.
This commit is contained in:
3wc 2020-12-26 12:19:58 +02:00
parent 7f009f927b
commit 40ca8dfe93

128
abra
View File

@ -12,7 +12,7 @@ The cooperative cloud utility belt 🎩🐇
Usage: Usage:
abra [options] app new [--server=<server>] [--domain=<domain>] [--pass] [--auto] <app> abra [options] app new [--server=<server>] [--domain=<domain>] [--pass] [--auto] <app>
abra [options] app (list|ls) [--status] abra [options] app (list|ls) [--status] [--server=<server>]
abra [options] app <domain> deploy abra [options] app <domain> deploy
abra [options] app <domain> undeploy abra [options] app <domain> undeploy
abra [options] app <domain> config abra [options] app <domain> config
@ -31,9 +31,10 @@ Usage:
abra [options] app <domain> <command> [<arg>] abra [options] app <domain> <command> [<arg>]
abra [options] server add <host> [<user>] [<port>] abra [options] server add <host> [<user>] [<port>]
abra [options] server (list|ls) abra [options] server (list|ls)
abra [options] server rm <host> abra [options] server <host> rm
abra [options] server use <host> abra [options] server <host> use
abra [options] server init <host> abra [options] server <host> init
abra [options] server <host> apps [--status]
abra [options] upgrade abra [options] upgrade
Options: Options:
@ -144,12 +145,12 @@ 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() { return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() {
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() { printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() { [[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1497} printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1564}
usage=${DOC:40:1189}; digest=feaba; shorts=(-e -v -h -s '' '' '' '' '' '' '' '') usage=${DOC:40:1256}; digest=48295; shorts=(-h -e -v -s '' '' '' '' '' '' '' '')
longs=(--env --version --help --stack --server --domain --pass --auto --status --force --user --all) longs=(--help --env --version --stack --server --domain --pass --auto --status --force --user --all)
argcounts=(1 0 0 1 1 1 0 0 0 0 1 0); node_0(){ value __env 0; }; node_1(){ argcounts=(0 1 0 1 1 1 0 0 0 0 1 0); node_0(){ switch __help 0; }; node_1(){
switch __version 1; }; node_2(){ switch __help 2; }; node_3(){ value __stack 3 value __env 1; }; node_2(){ switch __version 2; }; node_3(){ value __stack 3; }
}; node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){ node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
switch __pass 6; }; node_7(){ switch __auto 7; }; node_8(){ switch __status 8; } switch __pass 6; }; node_7(){ switch __auto 7; }; node_8(){ switch __status 8; }
node_9(){ switch __force 9; }; node_10(){ value __user 10; }; node_11(){ node_9(){ switch __force 9; }; node_10(){ value __user 10; }; node_11(){
switch __all 11; }; node_12(){ value _app_ a; }; node_13(){ value _domain_ a; } switch __all 11; }; node_12(){ value _app_ a; }; node_13(){ value _domain_ a; }
@ -167,55 +168,56 @@ node_39(){ _command check; }; node_40(){ _command ps; }; node_41(){ _command run
}; node_42(){ _command secret; }; node_43(){ _command auto; }; node_44(){ }; node_42(){ _command secret; }; node_43(){ _command auto; }; node_44(){
_command generate; }; node_45(){ _command insert; }; node_46(){ _command server _command generate; }; node_45(){ _command insert; }; node_46(){ _command server
}; node_47(){ _command add; }; node_48(){ _command use; }; node_49(){ }; node_47(){ _command add; }; node_48(){ _command use; }; node_49(){
_command init; }; node_50(){ _command upgrade; }; node_51(){ optional 0 1 2 3; } _command init; }; node_50(){ _command apps; }; node_51(){ _command upgrade; }
node_52(){ optional 51; }; node_53(){ optional 4; }; node_54(){ optional 5; } node_52(){ optional 0 1 2 3; }; node_53(){ optional 52; }; node_54(){ optional 4
node_55(){ optional 6; }; node_56(){ optional 7; }; node_57(){ }; node_55(){ optional 5; }; node_56(){ optional 6; }; node_57(){ optional 7; }
required 52 27 28 53 54 55 56 12; }; node_58(){ either 29 30; }; node_59(){ node_58(){ required 53 27 28 54 55 56 57 12; }; node_59(){ either 29 30; }
required 58; }; node_60(){ optional 8; }; node_61(){ required 52 27 59 60; } node_60(){ required 59; }; node_61(){ optional 8; }; node_62(){
node_62(){ required 52 27 13 31; }; node_63(){ required 52 27 13 32; } required 53 27 60 61 54; }; node_63(){ required 53 27 13 31; }; node_64(){
node_64(){ required 52 27 13 33; }; node_65(){ either 34 35; }; node_66(){ required 53 27 13 32; }; node_65(){ required 53 27 13 33; }; node_66(){
required 65; }; node_67(){ optional 9; }; node_68(){ required 52 27 13 66 67; } either 34 35; }; node_67(){ required 66; }; node_68(){ optional 9; }; node_69(){
node_69(){ optional 14; }; node_70(){ required 52 27 13 36 69; }; node_71(){ required 53 27 13 67 68; }; node_70(){ optional 14; }; node_71(){
required 52 27 13 37; }; node_72(){ required 52 27 13 38 15 16; }; node_73(){ required 53 27 13 36 70; }; node_72(){ required 53 27 13 37; }; node_73(){
required 52 27 13 39; }; node_74(){ required 52 27 13 40; }; node_75(){ required 53 27 13 38 15 16; }; node_74(){ required 53 27 13 39; }; node_75(){
optional 10; }; node_76(){ oneormore 17; }; node_77(){ required 53 27 13 40; }; node_76(){ optional 10; }; node_77(){ oneormore 17; }
required 52 27 13 41 75 14 76; }; node_78(){ required 52 27 13 41 14 76; } node_78(){ required 53 27 13 41 76 14 77; }; node_79(){
node_79(){ required 52 27 13 42 43 55; }; node_80(){ optional 20; }; node_81(){ required 53 27 13 41 14 77; }; node_80(){ required 53 27 13 42 43 56; }
required 52 27 13 42 44 18 19 80 55; }; node_82(){ node_81(){ optional 20; }; node_82(){ required 53 27 13 42 44 18 19 81 56; }
required 52 27 13 42 45 18 19 21 55; }; node_83(){ either 18 11; }; node_84(){ node_83(){ required 53 27 13 42 45 18 19 21 56; }; node_84(){ either 18 11; }
required 83; }; node_85(){ required 52 27 13 42 66 84 55 67; }; node_86(){ node_85(){ required 84; }; node_86(){ required 53 27 13 42 67 85 56 68; }
optional 23; }; node_87(){ required 52 27 13 22 86; }; node_88(){ optional 25; } node_87(){ optional 23; }; node_88(){ required 53 27 13 22 87; }; node_89(){
node_89(){ optional 26; }; node_90(){ required 52 46 47 24 88 89; }; node_91(){ optional 25; }; node_90(){ optional 26; }; node_91(){ required 53 46 47 24 89 90
required 52 46 59; }; node_92(){ required 52 46 35 24; }; node_93(){ }; node_92(){ required 53 46 60; }; node_93(){ required 53 46 24 35; }
required 52 46 48 24; }; node_94(){ required 52 46 49 24; }; node_95(){ node_94(){ required 53 46 24 48; }; node_95(){ required 53 46 24 49; }
required 52 50; }; node_96(){ node_96(){ required 53 46 24 50 61; }; node_97(){ required 53 51; }; node_98(){
either 57 61 62 63 64 68 70 71 72 73 74 77 78 79 81 82 85 87 90 91 92 93 94 95 either 58 62 63 64 65 69 71 72 73 74 75 78 79 80 82 83 86 88 91 92 93 94 95 96 97
}; node_97(){ required 96; }; cat <<<' docopt_exit() { }; node_99(){ required 98; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1189}" >&2 [[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1256}" >&2
exit 1; }'; unset var___env var___version var___help var___stack var___server \ exit 1; }'; unset var___help var___env var___version var___stack var___server \
var___domain var___pass var___auto var___status var___force var___user \ var___domain var___pass var___auto var___status var___force var___user \
var___all var__app_ var__domain_ var__service_ var__src_ var__dst_ var__args_ \ var___all var__app_ var__domain_ var__service_ var__src_ var__dst_ var__args_ \
var__secret_ var__version_ var__cmd_ var__data_ var__command_ var__arg_ \ var__secret_ var__version_ var__cmd_ var__data_ var__command_ var__arg_ \
var__host_ var__user_ var__port_ var_app var_new var_list var_ls var_deploy \ var__host_ var__user_ var__port_ var_app var_new var_list var_ls var_deploy \
var_undeploy var_config var_delete var_rm var_logs var_multilogs var_cp \ var_undeploy var_config var_delete var_rm var_logs var_multilogs var_cp \
var_check var_ps var_run var_secret var_auto var_generate var_insert \ var_check var_ps var_run var_secret var_auto var_generate var_insert \
var_server var_add var_use var_init var_upgrade; parse 97 "$@" var_server var_add var_use var_init var_apps var_upgrade; parse 99 "$@"
local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__env" "${prefix}__version" \ local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__help" "${prefix}__env" \
"${prefix}__help" "${prefix}__stack" "${prefix}__server" "${prefix}__domain" \ "${prefix}__version" "${prefix}__stack" "${prefix}__server" \
"${prefix}__pass" "${prefix}__auto" "${prefix}__status" "${prefix}__force" \ "${prefix}__domain" "${prefix}__pass" "${prefix}__auto" "${prefix}__status" \
"${prefix}__user" "${prefix}__all" "${prefix}_app_" "${prefix}_domain_" \ "${prefix}__force" "${prefix}__user" "${prefix}__all" "${prefix}_app_" \
"${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" \ "${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
"${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" \ "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" \
"${prefix}_command_" "${prefix}_arg_" "${prefix}_host_" "${prefix}_user_" \ "${prefix}_data_" "${prefix}_command_" "${prefix}_arg_" "${prefix}_host_" \
"${prefix}_port_" "${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" \ "${prefix}_user_" "${prefix}_port_" "${prefix}app" "${prefix}new" \
"${prefix}deploy" "${prefix}undeploy" "${prefix}config" "${prefix}delete" \ "${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}undeploy" \
"${prefix}rm" "${prefix}logs" "${prefix}multilogs" "${prefix}cp" \ "${prefix}config" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
"${prefix}check" "${prefix}ps" "${prefix}run" "${prefix}secret" \ "${prefix}multilogs" "${prefix}cp" "${prefix}check" "${prefix}ps" \
"${prefix}auto" "${prefix}generate" "${prefix}insert" "${prefix}server" \ "${prefix}run" "${prefix}secret" "${prefix}auto" "${prefix}generate" \
"${prefix}add" "${prefix}use" "${prefix}init" "${prefix}upgrade" "${prefix}insert" "${prefix}server" "${prefix}add" "${prefix}use" \
"${prefix}init" "${prefix}apps" "${prefix}upgrade"
eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__env=${var___env:-}' eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__version=${var___version:-false}' eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__stack=${var___stack:-}' eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__server=${var___server:-}' eval "${prefix}"'__server=${var___server:-}'
eval "${prefix}"'__domain=${var___domain:-}' eval "${prefix}"'__domain=${var___domain:-}'
@ -256,9 +258,10 @@ eval "${prefix}"'insert=${var_insert:-false}'
eval "${prefix}"'server=${var_server:-false}' eval "${prefix}"'server=${var_server:-false}'
eval "${prefix}"'add=${var_add:-false}'; eval "${prefix}"'use=${var_use:-false}' eval "${prefix}"'add=${var_add:-false}'; eval "${prefix}"'use=${var_use:-false}'
eval "${prefix}"'init=${var_init:-false}' eval "${prefix}"'init=${var_init:-false}'
eval "${prefix}"'apps=${var_apps:-false}'
eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1 eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__env" "${prefix}__version" "${prefix}__help" \ declare -p "${prefix}__help" "${prefix}__env" "${prefix}__version" \
"${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \ "${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \
"${prefix}__auto" "${prefix}__status" "${prefix}__force" "${prefix}__user" \ "${prefix}__auto" "${prefix}__status" "${prefix}__force" "${prefix}__user" \
"${prefix}__all" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \ "${prefix}__all" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \
@ -270,7 +273,7 @@ declare -p "${prefix}__env" "${prefix}__version" "${prefix}__help" \
"${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}check" \ "${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}check" \
"${prefix}ps" "${prefix}run" "${prefix}secret" "${prefix}auto" \ "${prefix}ps" "${prefix}run" "${prefix}secret" "${prefix}auto" \
"${prefix}generate" "${prefix}insert" "${prefix}server" "${prefix}add" \ "${prefix}generate" "${prefix}insert" "${prefix}server" "${prefix}add" \
"${prefix}use" "${prefix}init" "${prefix}upgrade"; done; } "${prefix}use" "${prefix}init" "${prefix}apps" "${prefix}upgrade"; done; }
# docopt parser above, complete command for generating this parser is `docopt.sh abra` # docopt parser above, complete command for generating this parser is `docopt.sh abra`
PROGRAM_NAME=$(basename "$0") PROGRAM_NAME=$(basename "$0")
@ -458,19 +461,28 @@ sub_app_ls (){
} }
sub_app_list (){ sub_app_list (){
SERVER="$abra___server"
if [ -z "$SERVER" ]; then
SERVER='*'
fi
shopt -s nullglob dotglob shopt -s nullglob dotglob
# shellcheck disable=SC2206 # shellcheck disable=SC2206
ENV_FILES=($ABRA_DIR/servers/*/*.env) ENV_FILES=($ABRA_DIR/servers/$SERVER/*.env)
shopt -u nullglob dotglob shopt -u nullglob dotglob
STATUS="$( [[ $abra___status == "true" ]] && echo "Y" )" STATUS="$( [[ $abra___status == "true" ]] && echo "Y" )"
if [ -n "$STATUS" ]; then if [ -n "$STATUS" ]; then
if [ -z "$SERVER" ]; then
get_servers get_servers
else
SERVERS=( "$SERVER" )
fi
local -a DEPLOYED_APPS # array local -a DEPLOYED_APPS # array
warning "Loading status from ${#SERVERS[@]} servers, patience advised.." warning "Loading status from ${#SERVERS[@]} server(s), patience advised.."
for SERVER in "${SERVERS[@]}"; do for SERVER in "${SERVERS[@]}"; do
SERVER="${SERVER##*/}" # basename SERVER="${SERVER##*/}" # basename
@ -953,6 +965,12 @@ sub_server_use() {
docker context use "$abra__host_" docker context use "$abra__host_"
} }
###### .. server <host> apps
sub_server_apps() {
abra___server="$abra__host_"
sub_app_list
}
####################################### #######################################
# Misc commands # Misc commands
####################################### #######################################