Local server list, more tidying
This commit is contained in:
		
							
								
								
									
										148
									
								
								abra
									
									
									
									
									
								
							
							
						
						
									
										148
									
								
								abra
									
									
									
									
									
								
							| @ -22,10 +22,10 @@ Usage: | ||||
|   abra [options] app <domain> secret generate <secret> <version> [<cmd>] | ||||
|   abra [options] app <domain> secret insert <secret> <version> <data> | ||||
|   abra [options] server add <host> [<user>] [<port>] | ||||
|   abra [options] server (list|ls) | ||||
|   abra [options] server rm <host> | ||||
|   abra [options] server use <host> | ||||
|   abra [options] server init <host> | ||||
|   abra [options] server ls | ||||
|   abra [options] upgrade | ||||
|   abra [options] <command> <args>... | ||||
|  | ||||
| @ -137,60 +137,62 @@ 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:1097} | ||||
| usage=${DOC:40:789}; digest=9b786; shorts=(-e -h -s -v '' '' '') | ||||
| longs=(--env --help --stack --version --server --domain --user) | ||||
| argcounts=(1 0 1 0 1 1 1); node_0(){ value __env 0; }; node_1(){ switch __help 1 | ||||
| }; node_2(){ value __stack 2; }; node_3(){ switch __version 3; }; node_4(){ | ||||
| value __server 4; }; node_5(){ value __domain 5; }; node_6(){ value __user 6; } | ||||
| node_7(){ value _app_ a; }; node_8(){ value _domain_ a; }; node_9(){ | ||||
| value _service_ a; }; node_10(){ value _src_ a; }; node_11(){ value _dst_ a; } | ||||
| node_12(){ value _args_ a true; }; node_13(){ value _secret_ a; }; node_14(){ | ||||
| value _version_ a; }; node_15(){ value _cmd_ a; }; node_16(){ value _data_ a; } | ||||
| node_17(){ value _host_ a; }; node_18(){ value _user_ a; }; node_19(){ | ||||
| value _port_ a; }; node_20(){ value _command_ a; }; node_21(){ _command app; } | ||||
| node_22(){ _command new; }; node_23(){ _command list; }; node_24(){ _command ls | ||||
| }; node_25(){ _command deploy; }; node_26(){ _command logs; }; node_27(){ | ||||
| _command multilogs; }; node_28(){ _command cp; }; node_29(){ _command run; } | ||||
| node_30(){ _command secret; }; node_31(){ _command generate; }; node_32(){ | ||||
| _command insert; }; node_33(){ _command server; }; node_34(){ _command add; } | ||||
| node_35(){ _command rm; }; node_36(){ _command use; }; node_37(){ _command init | ||||
| }; node_38(){ _command upgrade; }; node_39(){ optional 0 1 2 3; }; node_40(){ | ||||
| optional 39; }; node_41(){ optional 4 5; }; node_42(){ required 40 21 22 41 7; } | ||||
| node_43(){ either 23 24; }; node_44(){ required 43; }; node_45(){ | ||||
| required 40 21 44; }; node_46(){ required 40 21 8 25; }; node_47(){ optional 9 | ||||
| }; node_48(){ required 40 21 8 26 47; }; node_49(){ required 40 21 8 27; } | ||||
| node_50(){ required 40 21 8 28 10 11; }; node_51(){ optional 6; }; node_52(){ | ||||
| oneormore 12; }; node_53(){ required 40 21 8 29 51 9 52; }; node_54(){ | ||||
| printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1104} | ||||
| usage=${DOC:40:796}; digest=0e48b; shorts=(-v -e -h -s '' '' '') | ||||
| longs=(--version --env --help --stack --server --domain --user) | ||||
| argcounts=(0 1 0 1 1 1 1); node_0(){ switch __version 0; }; node_1(){ | ||||
| value __env 1; }; node_2(){ switch __help 2; }; node_3(){ value __stack 3; } | ||||
| node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){ | ||||
| value __user 6; }; node_7(){ value _app_ a; }; node_8(){ value _domain_ a; } | ||||
| node_9(){ value _service_ a; }; node_10(){ value _src_ a; }; node_11(){ | ||||
| value _dst_ a; }; node_12(){ value _args_ a true; }; node_13(){ value _secret_ a | ||||
| }; node_14(){ value _version_ a; }; node_15(){ value _cmd_ a; }; node_16(){ | ||||
| value _data_ a; }; node_17(){ value _host_ a; }; node_18(){ value _user_ a; } | ||||
| node_19(){ value _port_ a; }; node_20(){ value _command_ a; }; node_21(){ | ||||
| _command app; }; node_22(){ _command new; }; node_23(){ _command list; } | ||||
| node_24(){ _command ls; }; node_25(){ _command deploy; }; node_26(){ | ||||
| _command logs; }; node_27(){ _command multilogs; }; node_28(){ _command cp; } | ||||
| node_29(){ _command run; }; node_30(){ _command secret; }; node_31(){ | ||||
| _command generate; }; node_32(){ _command insert; }; node_33(){ _command server | ||||
| }; node_34(){ _command add; }; node_35(){ _command rm; }; node_36(){ | ||||
| _command use; }; node_37(){ _command init; }; node_38(){ _command upgrade; } | ||||
| node_39(){ optional 0 1 2 3; }; node_40(){ optional 39; }; node_41(){ | ||||
| optional 4 5; }; node_42(){ required 40 21 22 41 7; }; node_43(){ either 23 24 | ||||
| }; node_44(){ required 43; }; node_45(){ required 40 21 44; }; node_46(){ | ||||
| required 40 21 8 25; }; node_47(){ optional 9; }; node_48(){ | ||||
| required 40 21 8 26 47; }; node_49(){ required 40 21 8 27; }; node_50(){ | ||||
| required 40 21 8 28 10 11; }; node_51(){ optional 6; }; node_52(){ oneormore 12 | ||||
| }; node_53(){ required 40 21 8 29 51 9 52; }; node_54(){ | ||||
| required 40 21 8 29 9 52; }; node_55(){ optional 15; }; node_56(){ | ||||
| required 40 21 8 30 31 13 14 55; }; node_57(){ required 40 21 8 30 32 13 14 16 | ||||
| }; node_58(){ optional 18; }; node_59(){ optional 19; }; node_60(){ | ||||
| required 40 33 34 17 58 59; }; node_61(){ required 40 33 35 17; }; node_62(){ | ||||
| required 40 33 36 17; }; node_63(){ required 40 33 37 17; }; node_64(){ | ||||
| required 40 33 24; }; node_65(){ required 40 38; }; node_66(){ required 40 20 52 | ||||
| }; node_67(){ either 42 45 46 48 49 50 53 54 56 57 60 61 62 63 64 65 66; } | ||||
| node_68(){ required 67; }; cat <<<' docopt_exit() { | ||||
| [[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:789}" >&2; exit 1 | ||||
| }'; unset var___env var___help var___stack var___version var___server \ | ||||
| var___domain var___user var__app_ var__domain_ var__service_ var__src_ \ | ||||
| var__dst_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \ | ||||
| var__host_ var__user_ var__port_ var__command_ var_app var_new var_list var_ls \ | ||||
| var_deploy var_logs var_multilogs var_cp var_run var_secret var_generate \ | ||||
| var_insert var_server var_add var_rm var_use var_init var_upgrade; parse 68 "$@" | ||||
| local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__env" "${prefix}__help" \ | ||||
| "${prefix}__stack" "${prefix}__version" "${prefix}__server" \ | ||||
| "${prefix}__domain" "${prefix}__user" "${prefix}_app_" "${prefix}_domain_" \ | ||||
| "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" \ | ||||
| "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" \ | ||||
| "${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_command_" \ | ||||
| "${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \ | ||||
| "${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \ | ||||
| "${prefix}secret" "${prefix}generate" "${prefix}insert" "${prefix}server" \ | ||||
| "${prefix}add" "${prefix}rm" "${prefix}use" "${prefix}init" "${prefix}upgrade" | ||||
| required 40 33 34 17 58 59; }; node_61(){ required 40 33 44; }; node_62(){ | ||||
| required 40 33 35 17; }; node_63(){ required 40 33 36 17; }; node_64(){ | ||||
| required 40 33 37 17; }; node_65(){ required 40 38; }; node_66(){ | ||||
| required 40 20 52; }; node_67(){ | ||||
| either 42 45 46 48 49 50 53 54 56 57 60 61 62 63 64 65 66; }; node_68(){ | ||||
| required 67; }; cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2 | ||||
| printf "%s\n" "${DOC:40:796}" >&2; exit 1; }'; unset var___version var___env \ | ||||
| var___help var___stack var___server var___domain var___user var__app_ \ | ||||
| var__domain_ var__service_ var__src_ var__dst_ var__args_ var__secret_ \ | ||||
| var__version_ var__cmd_ var__data_ var__host_ var__user_ var__port_ \ | ||||
| var__command_ var_app var_new var_list var_ls var_deploy var_logs \ | ||||
| var_multilogs var_cp var_run var_secret var_generate var_insert var_server \ | ||||
| var_add var_rm var_use var_init var_upgrade; parse 68 "$@" | ||||
| local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__version" "${prefix}__env" \ | ||||
| "${prefix}__help" "${prefix}__stack" "${prefix}__server" "${prefix}__domain" \ | ||||
| "${prefix}__user" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \ | ||||
| "${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" \ | ||||
| "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" \ | ||||
| "${prefix}_user_" "${prefix}_port_" "${prefix}_command_" "${prefix}app" \ | ||||
| "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}logs" \ | ||||
| "${prefix}multilogs" "${prefix}cp" "${prefix}run" "${prefix}secret" \ | ||||
| "${prefix}generate" "${prefix}insert" "${prefix}server" "${prefix}add" \ | ||||
| "${prefix}rm" "${prefix}use" "${prefix}init" "${prefix}upgrade" | ||||
| eval "${prefix}"'__version=${var___version:-false}' | ||||
| eval "${prefix}"'__env=${var___env:-}' | ||||
| eval "${prefix}"'__help=${var___help:-false}' | ||||
| eval "${prefix}"'__stack=${var___stack:-}' | ||||
| eval "${prefix}"'__version=${var___version:-false}' | ||||
| eval "${prefix}"'__server=${var___server:-}' | ||||
| eval "${prefix}"'__domain=${var___domain:-}' | ||||
| eval "${prefix}"'__user=${var___user:-}'; eval "${prefix}"'_app_=${var__app_:-}' | ||||
| @ -221,8 +223,8 @@ eval "${prefix}"'use=${var_use:-false}' | ||||
| eval "${prefix}"'init=${var_init:-false}' | ||||
| eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1 | ||||
| [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do | ||||
| declare -p "${prefix}__env" "${prefix}__help" "${prefix}__stack" \ | ||||
| "${prefix}__version" "${prefix}__server" "${prefix}__domain" "${prefix}__user" \ | ||||
| declare -p "${prefix}__version" "${prefix}__env" "${prefix}__help" \ | ||||
| "${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__user" \ | ||||
| "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" \ | ||||
| "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" \ | ||||
| "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" "${prefix}_user_" \ | ||||
| @ -260,10 +262,6 @@ if [ -z "$COMPOSE_FILE" ]; then | ||||
|   COMPOSE_FILE="compose.yml" | ||||
| fi | ||||
|  | ||||
| if [ -z "$ABRA_STACK_DIR" ]; then | ||||
|   ABRA_STACK_DIR="stacks/$SERVICE" | ||||
| fi | ||||
|  | ||||
| ###### Safety checks | ||||
|  | ||||
| require_multitail() { | ||||
| @ -282,13 +280,6 @@ require_stack() { | ||||
|   fi | ||||
| } | ||||
|  | ||||
| require_stack_dir() { | ||||
|   # FIXME 3wc: replace with APP_DIR | ||||
|   if [ -z "$ABRA_STACK_DIR" ] || [ ! -d "$ABRA_STACK_DIR" ]; then | ||||
|     error "can't find \$ABRA_STACK_DIR '$ABRA_STACK_DIR'" | ||||
|   fi | ||||
| } | ||||
|  | ||||
| # FIXME 3wc: update or remove | ||||
| if [ -z "$ABRA_ENV" ] && [ -f .envrc ] && type direnv > /dev/null 2>&1 && ! direnv status | grep -q 'Found RC allowed true'; then | ||||
|   error "direnv is blocked, run direnv allow" | ||||
| @ -302,12 +293,20 @@ load_custom_commands() { | ||||
|     source abra-commands.sh | ||||
|   fi | ||||
|  | ||||
|   if [ -f "$ABRA_STACK_DIR/abra-commands.sh" ]; then | ||||
|   if [ -f "$APP_DIR/abra-commands.sh" ]; then | ||||
|     # shellcheck disable=SC1090 | ||||
|     source "$ABRA_STACK_DIR/abra-commands.sh" | ||||
|     source "$APP_DIR/abra-commands.sh" | ||||
|   fi | ||||
| } | ||||
|  | ||||
| ###### FIXME 3wc: name this section | ||||
|  | ||||
| get_servers() { | ||||
|   shopt -s nullglob dotglob | ||||
|   SERVERS=(~/.abra/servers/*) | ||||
|   shopt -u nullglob dotglob | ||||
| } | ||||
|  | ||||
| load_instance() { | ||||
|   DOMAIN="$abra__domain_" | ||||
|   ENV_FILE=$(find ~/.abra -name "$DOMAIN.env") | ||||
| @ -357,14 +356,12 @@ sub_app_list (){ | ||||
|   printf "%s lovely apps:\n\n" "${#ENV_FILES[@]}" | ||||
|  | ||||
|   for i in "${!ENV_FILES[@]}"; do | ||||
|     local PARTS | ||||
|  | ||||
|     # Do this inside the loop to include in pipe to `column` | ||||
|     if [ "$i" == 0 ]; then | ||||
|       printf "  DOMAIN\tAPP\tSERVER\n  --\t--\t--\n" | ||||
|     fi | ||||
|  | ||||
|     ENV_FILE="${ENV_FILES[$i]}" | ||||
|     local ENV_FILE="${ENV_FILES[$i]}" | ||||
|  | ||||
|     IFS='/' read -r -a PARTS <<< "$ENV_FILE" | ||||
|  | ||||
| @ -375,22 +372,19 @@ sub_app_list (){ | ||||
|     APP="$(source "$ENV_FILE" && echo "$APP")" | ||||
|     printf "  %s\t%s\t%s\n" "$DOMAIN" "$APP" "$SERVER" | ||||
|   done | column -s'	' -t | ||||
|   # Align table `-t`  based on tab characters -s`^V<Tab>` | ||||
|   # Align table `-t` based on tab characters -s`^V<Tab>` | ||||
| } | ||||
|  | ||||
| ###### .. app new [--domain=<domain> --server=<server>] | ||||
| sub_app_new (){ | ||||
|   require_abra_dir | ||||
|   get_servers | ||||
|  | ||||
|   APP=$abra__app_ | ||||
|   SERVER=$abra___server | ||||
|   DOMAIN=$abra___domain | ||||
|  | ||||
|   if [ -z "$SERVER" ]; then | ||||
|     shopt -s nullglob dotglob | ||||
|     SERVERS=(~/.abra/servers/*) | ||||
|     shopt -u nullglob dotglob | ||||
|  | ||||
|     echo "Where would you like to put $APP?" | ||||
|  | ||||
|     echo -n "$(tput setaf 4)" | ||||
| @ -677,7 +671,15 @@ sub_server_use() { | ||||
| } | ||||
|  | ||||
| sub_server_ls() { | ||||
|   docker context ls | ||||
|   sub_server_list | ||||
| } | ||||
|  | ||||
| sub_server_list() { | ||||
|   get_servers | ||||
|   printf "%s servers:\n\n" "${#SERVERS[@]}" | ||||
|   for SERVER in "${SERVERS[@]}"; do | ||||
|     echo "  ${SERVER##*/}" | ||||
|   done | ||||
| } | ||||
|  | ||||
| ####################################### | ||||
|  | ||||
		Reference in New Issue
	
	Block a user