subcommand restructure and bashstyle refactor. closes #1579

This commit is contained in:
Michael S. Hobbs
2016-03-01 13:26:35 -08:00
committed by Michael Hobbs
parent 76e27f0333
commit 89f289b433
105 changed files with 1969 additions and 1306 deletions

View File

@@ -1,43 +1,8 @@
#!/usr/bin/env bash
[[ " docker-options docker-options:add docker-options:remove help docker-options:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
[[ " help docker-options:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
declare APP # global assigned in case
case "$1" in
# Display applications docker options
docker-options)
verify_app_name "$2" && APP="$2"
read -ra passed_phases <<< "$(get_phases "$3")"
if [[ ! "${passed_phases[@]}" ]]; then
display_all_phases_options
else
display_passed_phases_options passed_phases[@]
fi
;;
# Add a docker option to application
docker-options:add)
verify_app_name "$2" && APP="$2"
read -ra passed_phases <<< "$(get_phases "$3")"
shift 3 # everything else passed is the docker option
passed_docker_option="$*"
[[ -z "$passed_docker_option" ]] && dokku_log_fail "Please specify docker options to add to the phase"
add_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
;;
# Remove a docker option from application
docker-options:remove)
verify_app_name "$2" && APP="$2"
read -ra passed_phases <<< "$(get_phases "$3")"
shift 3 # everything else passed is the docker option
[[ -z ${passed_docker_option="$@"} ]] && dokku_log_fail "Please specify docker options to add to the phase"
remove_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
;;
# Display usage help
help | docker-options:help)
cat<<EOF
docker-options <app>, Display app's Docker options for all phases

View File

@@ -5,6 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
AVAILABLE_PHASES=(build deploy run)
get_phase_file_path() {
local desc="return docker-options config file path for specified phase"
local phase_file_prefix="DOCKER_OPTIONS_"
local phase=$1
[[ "$DOKKU_ROOT" && "$APP" && "$phase_file_prefix" && "$phase" ]] || dokku_log_fail "Error: phase_file_path is incomplete."
@@ -12,6 +13,7 @@ get_phase_file_path() {
}
get_phases() {
local desc="returns array of passed passes if all are in allowed array"
local passed_phases_list="$1"
local -r phases_allowed=$(sed -e 's/ /\|/g' <<< "${AVAILABLE_PHASES[@]}")
local phase
@@ -28,6 +30,7 @@ get_phases() {
}
create_phase_file_if_required() {
local desc="create phase file"
local phase_file_path="$1"
[[ -f "$phase_file_path" ]] || {
touch "$phase_file_path"
@@ -35,6 +38,7 @@ create_phase_file_if_required() {
}
display_phase_options() {
local desc="print docker-options for specified phase"
local phase="$1"
local phase_file_path="$2"
echo "${phase^} options:"
@@ -42,6 +46,7 @@ display_phase_options() {
}
display_all_phases_options() {
local desc="print docker-options for all phases"
local phases=("${AVAILABLE_PHASES[@]}")
for phase in "${phases[@]}"; do
local phase_file_path
@@ -53,6 +58,7 @@ display_all_phases_options() {
}
display_passed_phases_options() {
local desc="print docker options for list of specified phases"
local passed_phases=("${!1}")
local phase
for phase in "${passed_phases[@]}"; do
@@ -67,6 +73,7 @@ display_passed_phases_options() {
}
add_passed_docker_option() {
local desc="adds docker option to specified phases"
local passed_phases=("${!1}")
shift
local passed_option_string="$*"
@@ -82,6 +89,7 @@ add_passed_docker_option() {
}
remove_passed_docker_option() {
local desc="removes docker option from specified phases"
local passed_phases=("${!1}")
shift
local passed_option_string="$*"

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
docker_options_add_cmd() {
local desc="Add a docker option to application"
local cmd="docker-options:add"
verify_app_name "$2" && local APP="$2"
read -ra passed_phases <<< "$(get_phases "$3")"
shift 3 # everything else passed is the docker option
passed_docker_option="$*"
[[ -z "$passed_docker_option" ]] && dokku_log_fail "Please specify docker options to add to the phase"
add_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
}
docker_options_add_cmd "$@"

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
docker_options_main_cmd() {
local desc="Display applications docker options"
local cmd="docker-options"
verify_app_name "$2" && local APP="$2"
read -ra passed_phases <<< "$(get_phases "$3")"
if [[ ! "${passed_phases[@]}" ]]; then
display_all_phases_options
else
display_passed_phases_options passed_phases[@]
fi
}
docker_options_main_cmd "$@"

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
docker_options_remove_cmd() {
local desc="Remove a docker option from application"
local cmd="docker-options:remove"
verify_app_name "$2" && local APP="$2"
read -ra passed_phases <<< "$(get_phases "$3")"
shift 3 # everything else passed is the docker option
[[ -z ${passed_docker_option="$@"} ]] && dokku_log_fail "Please specify docker options to add to the phase"
remove_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
}
docker_options_remove_cmd "$@"