Use docopts variables
continuous-integration/drone/push Build is failing Details

Ref #18
This commit is contained in:
3wc 2020-10-26 13:33:06 +02:00
parent 6cf7cf843a
commit 983e4af08c
2 changed files with 28 additions and 44 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
coverage/
/.venv

71
abra
View File

@ -26,8 +26,8 @@ View logs from running applications:
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
cp <src> <dest> copy files to a container
run <service> <cmd> run <cmd> in <service>'s container
Manage servers:
server add <host> [user] [port] add docker context
@ -135,8 +135,8 @@ 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:1345}
usage=${DOC:40:131}; digest=f2937; shorts=(-c -e -h -s -v)
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1352}
usage=${DOC:40:131}; digest=3774c; shorts=(-c -e -h -s -v)
longs=(--config --env --help --stack --version); argcounts=(1 1 0 1 0)
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(){
@ -193,7 +193,6 @@ parse_subcommand() {
if [ -n "$PREFIX" ]; then
PPREFIX="_$2"
SPREFIX="$2 "
SSPREFIX=" $2"
fi
case $SUBCOMMAND in
@ -204,9 +203,7 @@ parse_subcommand() {
shift 2
"sub${PPREFIX}_${SUBCOMMAND}" "$@"
if [ $? = 127 ]; then
echo "Error: '$SPREFIX$SUBCOMMAND' is not a known subcommand." >&2
echo " Run '$PROGRAM_NAME$SSPREFIX --help' for a list of known subcommands." >&2
exit 1
error "Error: '$SPREFIX$SUBCOMMAND' is not a known subcommand."
fi
;;
esac
@ -227,37 +224,6 @@ success() {
###### Top-level arguments
ABRA_CONFIG=abra.yml
if [ "$1" == "-c" ]; then
ABRA_CONFIG=$2
shift 2
fi
if [ "$1" == "-e" ]; then
ABRA_ENV=$2
shift 2
fi
if [ "$1" == "-a" ]; then
STACK_NAME=$2
shift 2
fi
###### Load config
if [ -f "$ABRA_CONFIG" ]; then
require_yq
if yml_pattern_exists stack_name; then
STACK_NAME=$(yq read "$ABRA_CONFIG" stack_name)
fi
# FIXME load other variables somehow
fi
if [ -n "$ABRA_ENV" ]; then
# shellcheck disable=SC1090
source "$ABRA_ENV" || error "Unable to load env from '$ABRA_ENV'"
fi
###### Default settings
@ -598,13 +564,30 @@ sub_volume() {
###### Main
# SUBCOMMAND=$1
# shift
# shellcheck disable=SC2086,SC2068
# parse_subcommand $SUBCOMMAND "" $@
abra() {
declare abra___stack abra___env abra___config abra__command_ abra__args_
DOCOPT_PREFIX=abra_
eval "$(docopt "$@")"
STACK_NAME=$abra___stack
if [ -n "$abra___env" ]; then
# shellcheck disable=SC1090
source "$abra___env" || error "Unable to load env from '$abra___env'"
fi
if [ -n "$abra___config" ]; then
require_yq
if yml_pattern_exists stack_name; then
STACK_NAME=$(yq read "$ABRA_CONFIG" stack_name)
fi
# FIXME load other variables somehow
fi
# shellcheck disable=SC2086
"sub_${abra__command_}" ${abra__args_[*]}
}
abra "$@"