refactor: unify command declaration across codebase

This commit is contained in:
Jose Diaz-Gonzalez
2020-02-10 01:40:30 -05:00
parent b0abeb49dd
commit e67b96780d
108 changed files with 475 additions and 315 deletions

View File

@@ -6,15 +6,16 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
cmd-enter-default() {
declare desc="enters running app container of specified proc type"
local cmd="enter"
local APP="$2"
local CONTAINER_TYPE="$3"
declare cmd="enter"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" CONTAINER_TYPE="$2" CONTAINER_ID_FLAG="$3" CONTAINER_ID="$4"
local IMAGE_TAG=$(get_running_image_tag "$APP")
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
verify_app_name "$APP"
local AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP"))
if [[ -z "$3" ]]; then
if [[ -z "$CONTAINER_TYPE" ]]; then
if [[ ${#AVAILABLE_CONTAINER_TYPES[@]} -gt 1 ]]; then
dokku_log_warn "No container type specified."
dokku_log_fail "Available types for app ($APP): ${AVAILABLE_CONTAINER_TYPES[*]}"
@@ -23,9 +24,9 @@ cmd-enter-default() {
fi
fi
if [[ "$3" == "--container-id" ]]; then
if [[ "$CONTAINER_ID_FLAG" == "--container-id" ]]; then
local DOKKU_APP_CIDS=($(get_app_container_ids "$APP"))
if [[ -z "$4" ]]; then
if [[ -z "$CONTAINER_ID" ]]; then
dokku_log_warn "No container id specified."
dokku_log_fail "Available ids for app ($APP): ${DOKKU_APP_CIDS[*]}"
fi
@@ -34,7 +35,7 @@ cmd-enter-default() {
dokku_log_fail "Available ids for app ($APP): ${DOKKU_APP_CIDS[*]}"
fi
local ID=$(printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -e "^$4")
shift 4
shift 3
else
local DOKKU_APP_CIDS=($(get_app_container_ids "$APP" "$CONTAINER_TYPE"))
local ID=${DOKKU_APP_CIDS[0]}
@@ -42,10 +43,10 @@ cmd-enter-default() {
dokku_log_warn "No containers found for type '$CONTAINER_TYPE'"
dokku_log_fail "Available types for app ($APP): ${AVAILABLE_CONTAINER_TYPES[*]}"
fi
if [[ $3 ]]; then
shift 3
else
if [[ "$CONTAINER_ID_FLAG" ]]; then
shift 2
else
shift 1
fi
fi