Load custom commands in a function

This commit is contained in:
3wc 2020-10-26 13:46:54 +02:00
parent b68bfdfb43
commit b49b510c43

44
abra
View File

@ -222,9 +222,6 @@ success() {
echo "$(tput setaf 2)$*$(tput sgr0)"
}
###### Top-level arguments
###### Default settings
if [ -z "$COMPOSE_FILE" ]; then
@ -235,15 +232,6 @@ if [ -z "$ABRA_STACK_DIR" ]; then
ABRA_STACK_DIR="stacks/$SERVICE"
fi
load_context() {
if [ -z "$DOCKER_CONTEXT" ]; then
warning "\$DOCKER_CONTEXT not set, (slowly) looking it up"
# shellcheck disable=SC2063
DOCKER_CONTEXT=$(docker context ls | grep '*' | cut -d' ' -f1)
# FIXME 3wc: make sure grep doesn't parse this, we're want a literal '*'
fi
}
###### Safety checks
require_yq() {
@ -274,17 +262,29 @@ if [ -z "$ABRA_ENV" ] && [ -f .envrc ] && type direnv > /dev/null 2>&1 && ! dire
error "direnv is blocked, run direnv allow"
fi
###### Custom commands
###### Run-time loading
if [ -f abra-commands.sh ]; then
# shellcheck disable=SC1091
source abra-commands.sh
fi
load_custom_commands() {
if [ -f abra-commands.sh ]; then
# shellcheck disable=SC1091
source abra-commands.sh
fi
if [ -f "$ABRA_STACK_DIR/abra-commands.sh" ]; then
# shellcheck disable=SC1090
source "$ABRA_STACK_DIR/abra-commands.sh"
fi
if [ -f "$ABRA_STACK_DIR/abra-commands.sh" ]; then
# shellcheck disable=SC1090
source "$ABRA_STACK_DIR/abra-commands.sh"
fi
}
load_context() {
# Load current context from env or Docker
if [ -z "$DOCKER_CONTEXT" ]; then
warning "\$DOCKER_CONTEXT not set, (slowly) looking it up"
# shellcheck disable=SC2063
DOCKER_CONTEXT=$(docker context ls | grep '*' | cut -d' ' -f1)
# make sure grep doesn't parse this, we want a literal '*'
fi
}
###### Subcommand `secret`
@ -586,6 +586,8 @@ abra() {
# FIXME load other variables somehow
fi
load_custom_commands
# shellcheck disable=SC2086
"sub_${abra__command_}" ${abra__args_[*]}
}