Fix logs, cp, `multilogs

Ref #18
This commit is contained in:
3wc 2020-10-26 16:54:55 +02:00
parent c50b1d8760
commit b59e902d18

142
abra
View File

@ -8,9 +8,9 @@ The cooperative cloud utility belt 🎩🐇
Usage: Usage:
abra [options] deploy abra [options] deploy
abra [options] upgrade abra [options] upgrade
abra [options] logs [<app>] abra [options] logs [<service>]
abra [options] multilogs [<app>] abra [options] multilogs
abra [options] cp (<app>:<path> <path>|<path> <app>:<path>) abra [options] cp <src> <dst>
abra [options] run [--user=<user>] <app> <args>... abra [options] run [--user=<user>] <app> <args>...
abra [options] run <app> <args>... abra [options] run <app> <args>...
abra [options] secret generate <secret> <version> [<cmd>] abra [options] secret generate <secret> <version> [<cmd>]
@ -20,6 +20,7 @@ Usage:
abra [options] server use <host> abra [options] server use <host>
abra [options] server init <host> abra [options] server init <host>
abra [options] server ls abra [options] server ls
abra [options] <command> <args>...
Options: Options:
-c, --config=<path> Stack configuration to use -c, --config=<path> Stack configuration to use
@ -134,58 +135,59 @@ 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:1102} printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1105}
usage=${DOC:40:574}; digest=fab9b; shorts=(-h -v -e -c -s '') usage=${DOC:40:577}; digest=fa67f; shorts=(-s -e -v -h -c '')
longs=(--help --version --env --config --stack --user); argcounts=(0 0 1 1 1 1) longs=(--stack --env --version --help --config --user); argcounts=(1 1 0 0 1 1)
node_0(){ switch __help 0; }; node_1(){ switch __version 1; }; node_2(){ node_0(){ value __stack 0; }; node_1(){ value __env 1; }; node_2(){
value __env 2; }; node_3(){ value __config 3; }; node_4(){ value __stack 4; } switch __version 2; }; node_3(){ switch __help 3; }; node_4(){ value __config 4
node_5(){ value __user 5; }; node_6(){ value _app_ a; }; node_7(){ }; node_5(){ value __user 5; }; node_6(){ value _service_ a; }; node_7(){
value _app___path_ a; }; node_8(){ value _path_ a; }; node_9(){ value _src_ a; }; node_8(){ value _dst_ a; }; node_9(){ value _app_ a; }
value _args_ a true; }; node_10(){ value _secret_ a; }; node_11(){ node_10(){ value _args_ a true; }; node_11(){ value _secret_ a; }; node_12(){
value _version_ a; }; node_12(){ value _cmd_ a; }; node_13(){ value _data_ a; } value _version_ a; }; node_13(){ value _cmd_ a; }; node_14(){ value _data_ a; }
node_14(){ value _host_ a; }; node_15(){ value _user_ a; }; node_16(){ node_15(){ value _host_ a; }; node_16(){ value _user_ a; }; node_17(){
value _port_ a; }; node_17(){ _command deploy; }; node_18(){ _command upgrade; } value _port_ a; }; node_18(){ value _command_ a; }; node_19(){ _command deploy
node_19(){ _command logs; }; node_20(){ _command multilogs; }; node_21(){ }; node_20(){ _command upgrade; }; node_21(){ _command logs; }; node_22(){
_command cp; }; node_22(){ _command run; }; node_23(){ _command secret; } _command multilogs; }; node_23(){ _command cp; }; node_24(){ _command run; }
node_24(){ _command generate; }; node_25(){ _command insert; }; node_26(){ node_25(){ _command secret; }; node_26(){ _command generate; }; node_27(){
_command server; }; node_27(){ _command add; }; node_28(){ _command rm; } _command insert; }; node_28(){ _command server; }; node_29(){ _command add; }
node_29(){ _command use; }; node_30(){ _command init; }; node_31(){ _command ls node_30(){ _command rm; }; node_31(){ _command use; }; node_32(){ _command init
}; node_32(){ optional 0 1 2 3 4; }; node_33(){ optional 32; }; node_34(){ }; node_33(){ _command ls; }; node_34(){ optional 0 1 2 3 4; }; node_35(){
required 33 17; }; node_35(){ required 33 18; }; node_36(){ optional 6; } optional 34; }; node_36(){ required 35 19; }; node_37(){ required 35 20; }
node_37(){ required 33 19 36; }; node_38(){ required 33 20 36; }; node_39(){ node_38(){ optional 6; }; node_39(){ required 35 21 38; }; node_40(){
required 7 8; }; node_40(){ required 8 7; }; node_41(){ either 39 40; } required 35 22; }; node_41(){ required 35 23 7 8; }; node_42(){ optional 5; }
node_42(){ required 41; }; node_43(){ required 33 21 42; }; node_44(){ node_43(){ oneormore 10; }; node_44(){ required 35 24 42 9 43; }; node_45(){
optional 5; }; node_45(){ oneormore 9; }; node_46(){ required 33 22 44 6 45; } required 35 24 9 43; }; node_46(){ optional 13; }; node_47(){
node_47(){ required 33 22 6 45; }; node_48(){ optional 12; }; node_49(){ required 35 25 26 11 12 46; }; node_48(){ required 35 25 27 11 12 14; }
required 33 23 24 10 11 48; }; node_50(){ required 33 23 25 10 11 13; } node_49(){ optional 16; }; node_50(){ optional 17; }; node_51(){
node_51(){ optional 15; }; node_52(){ optional 16; }; node_53(){ required 35 28 29 15 49 50; }; node_52(){ required 35 28 30 15; }; node_53(){
required 33 26 27 14 51 52; }; node_54(){ required 33 26 28 14; }; node_55(){ required 35 28 31 15; }; node_54(){ required 35 28 32 15; }; node_55(){
required 33 26 29 14; }; node_56(){ required 33 26 30 14; }; node_57(){ required 35 28 33; }; node_56(){ required 35 18 43; }; node_57(){
required 33 26 31; }; node_58(){ either 36 37 39 40 41 44 45 47 48 51 52 53 54 55 56; }; node_58(){ required 57
either 34 35 37 38 43 46 47 49 50 53 54 55 56 57; }; node_59(){ required 58; } }; cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2
cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2 printf "%s\n" "${DOC:40:577}" >&2; exit 1; }'; unset var___stack var___env \
printf "%s\n" "${DOC:40:574}" >&2; exit 1; }'; unset var___help var___version \ var___version var___help var___config var___user var__service_ var__src_ \
var___env var___config var___stack var___user var__app_ var__app___path_ \ var__dst_ var__app_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \
var__path_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \ var__host_ var__user_ var__port_ var__command_ var_deploy var_upgrade var_logs \
var__host_ var__user_ var__port_ var_deploy var_upgrade var_logs var_multilogs \ var_multilogs var_cp var_run var_secret var_generate var_insert var_server \
var_cp var_run var_secret var_generate var_insert var_server var_add var_rm \ var_add var_rm var_use var_init var_ls; parse 58 "$@"
var_use var_init var_ls; parse 59 "$@"; local prefix=${DOCOPT_PREFIX:-''} local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__stack" "${prefix}__env" \
unset "${prefix}__help" "${prefix}__version" "${prefix}__env" \ "${prefix}__version" "${prefix}__help" "${prefix}__config" "${prefix}__user" \
"${prefix}__config" "${prefix}__stack" "${prefix}__user" "${prefix}_app_" \ "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" "${prefix}_app_" \
"${prefix}_app___path_" "${prefix}_path_" "${prefix}_args_" \ "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" \
"${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" \ "${prefix}_data_" "${prefix}_host_" "${prefix}_user_" "${prefix}_port_" \
"${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}deploy" \ "${prefix}_command_" "${prefix}deploy" "${prefix}upgrade" "${prefix}logs" \
"${prefix}upgrade" "${prefix}logs" "${prefix}multilogs" "${prefix}cp" \ "${prefix}multilogs" "${prefix}cp" "${prefix}run" "${prefix}secret" \
"${prefix}run" "${prefix}secret" "${prefix}generate" "${prefix}insert" \ "${prefix}generate" "${prefix}insert" "${prefix}server" "${prefix}add" \
"${prefix}server" "${prefix}add" "${prefix}rm" "${prefix}use" "${prefix}init" \ "${prefix}rm" "${prefix}use" "${prefix}init" "${prefix}ls"
"${prefix}ls"; eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__config=${var___config:-}'
eval "${prefix}"'__stack=${var___stack:-}' eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__user=${var___user:-}'; eval "${prefix}"'_app_=${var__app_:-}' eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'_app___path_=${var__app___path_:-}' eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'_path_=${var__path_:-}' eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__config=${var___config:-}'
eval "${prefix}"'__user=${var___user:-}'
eval "${prefix}"'_service_=${var__service_:-}'
eval "${prefix}"'_src_=${var__src_:-}'; eval "${prefix}"'_dst_=${var__dst_:-}'
eval "${prefix}"'_app_=${var__app_:-}'
if declare -p var__args_ >/dev/null 2>&1; then if declare -p var__args_ >/dev/null 2>&1; then
eval "${prefix}"'_args_=("${var__args_[@]}")'; else eval "${prefix}"'_args_=()' eval "${prefix}"'_args_=("${var__args_[@]}")'; else eval "${prefix}"'_args_=()'
fi; eval "${prefix}"'_secret_=${var__secret_:-}' fi; eval "${prefix}"'_secret_=${var__secret_:-}'
@ -194,6 +196,7 @@ eval "${prefix}"'_cmd_=${var__cmd_:-}'; eval "${prefix}"'_data_=${var__data_:-}'
eval "${prefix}"'_host_=${var__host_:-}' eval "${prefix}"'_host_=${var__host_:-}'
eval "${prefix}"'_user_=${var__user_:-}' eval "${prefix}"'_user_=${var__user_:-}'
eval "${prefix}"'_port_=${var__port_:-}' eval "${prefix}"'_port_=${var__port_:-}'
eval "${prefix}"'_command_=${var__command_:-}'
eval "${prefix}"'deploy=${var_deploy:-false}' eval "${prefix}"'deploy=${var_deploy:-false}'
eval "${prefix}"'upgrade=${var_upgrade:-false}' eval "${prefix}"'upgrade=${var_upgrade:-false}'
eval "${prefix}"'logs=${var_logs:-false}' eval "${prefix}"'logs=${var_logs:-false}'
@ -207,15 +210,16 @@ eval "${prefix}"'add=${var_add:-false}'; eval "${prefix}"'rm=${var_rm:-false}'
eval "${prefix}"'use=${var_use:-false}' eval "${prefix}"'use=${var_use:-false}'
eval "${prefix}"'init=${var_init:-false}'; eval "${prefix}"'ls=${var_ls:-false}' eval "${prefix}"'init=${var_init:-false}'; eval "${prefix}"'ls=${var_ls:-false}'
local docopt_i=1; [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2 local docopt_i=1; [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2
for ((;docopt_i>0;docopt_i--)); do declare -p "${prefix}__help" \ for ((;docopt_i>0;docopt_i--)); do declare -p "${prefix}__stack" \
"${prefix}__version" "${prefix}__env" "${prefix}__config" "${prefix}__stack" \ "${prefix}__env" "${prefix}__version" "${prefix}__help" "${prefix}__config" \
"${prefix}__user" "${prefix}_app_" "${prefix}_app___path_" "${prefix}_path_" \ "${prefix}__user" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
"${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" \ "${prefix}_app_" "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" \
"${prefix}_data_" "${prefix}_host_" "${prefix}_user_" "${prefix}_port_" \ "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" "${prefix}_user_" \
"${prefix}deploy" "${prefix}upgrade" "${prefix}logs" "${prefix}multilogs" \ "${prefix}_port_" "${prefix}_command_" "${prefix}deploy" "${prefix}upgrade" \
"${prefix}cp" "${prefix}run" "${prefix}secret" "${prefix}generate" \ "${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \
"${prefix}insert" "${prefix}server" "${prefix}add" "${prefix}rm" \ "${prefix}secret" "${prefix}generate" "${prefix}insert" "${prefix}server" \
"${prefix}use" "${prefix}init" "${prefix}ls"; done; } "${prefix}add" "${prefix}rm" "${prefix}use" "${prefix}init" "${prefix}ls"; 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")
@ -450,7 +454,7 @@ sub_multilogs() {
sub_logs (){ sub_logs (){
require_stack require_stack
SERVICE=$1 SERVICE="${abra__service_}"
if [ -z "$SERVICE" ]; then if [ -z "$SERVICE" ]; then
warning "No \$SERVICE provided, running multilogs" warning "No \$SERVICE provided, running multilogs"
@ -480,8 +484,8 @@ sub_logs (){
sub_cp() { sub_cp() {
require_stack require_stack
SOURCE=$1 SOURCE="${abra__src_}"
DEST=$2 DEST="${abra__dst_}"
SERVICE=$(echo "$SOURCE" | grep -o '^[^:]\+:' || echo "$DEST" | grep -o '^[^:]\+:') SERVICE=$(echo "$SOURCE" | grep -o '^[^:]\+:' || echo "$DEST" | grep -o '^[^:]\+:')
SERVICE=$(echo "$SERVICE" | tr -d ':') SERVICE=$(echo "$SERVICE" | tr -d ':')
@ -510,7 +514,7 @@ sub_cp() {
###### Subcommand `context` ###### Subcommand `context`
sub_server_init() { sub_server_init() {
export DOCKER_CONTEXT="$1" export DOCKER_CONTEXT="${abra__host_}"
if [ -n "$DOCKER_CONTEXT" ]; then if [ -n "$DOCKER_CONTEXT" ]; then
load_context load_context
@ -570,11 +574,11 @@ sub_volume() {
###### Main ###### Main
abra() { abra() {
# TODO (3wc): we either need to do this, or add s'hellcheck disable' all over # TODO (3wc): we either need to do this, or add 'shellcheck disable' all over
# the place to handle the dynamically-defined vars # the place to handle the dynamically-defined vars
declare abra___stack abra___env abra___config abra__command_ abra__args_ \ declare abra___stack abra___env abra___config abra__command_ abra__args_ \
abra__secret_ abra__version_ abra__data_ abra___user abra__host_ \ abra__secret_ abra__version_ abra__data_ abra___user abra__host_ \
abra__app_ abra__port_ abra__user_ abra__app_ abra__port_ abra__user_ abra__service_ abra__src_ abra__dst_
DOCOPT_PREFIX=abra_ DOCOPT_PREFIX=abra_
eval "$(docopt "$@")" eval "$(docopt "$@")"