From 99f1f1b6d3827af8969ea1aadbeb04057fd8b9c8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 31 Aug 2015 23:03:52 -0400 Subject: [PATCH] Move config arg parsing into config/functions --- plugins/config/commands | 39 +++++---------------------------------- plugins/config/functions | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/plugins/config/commands b/plugins/config/commands index edb03c309..2ec781ce2 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" +source "$PLUGIN_PATH/config/functions" config_create () { [ -f $ENV_FILE ] || { @@ -46,36 +47,6 @@ config_write() { rm -f $ENV_FILE_TEMP } -parse_config_args() { - case "$2" in - --global) - ENV_FILE="$DOKKU_ROOT/ENV" - DOKKU_CONFIG_TYPE="global" - DOKKU_CONFIG_RESTART=false - ;; - --no-restart) - APP="$3" - ENV_FILE="$DOKKU_ROOT/$APP/ENV" - DOKKU_CONFIG_RESTART=false - DOKKU_CONFIG_TYPE="app" - set -- "${@:1:1}" "${@:3}" - esac - - APP=${APP:="$2"} - ENV_FILE=${ENV_FILE:="$DOKKU_ROOT/$APP/ENV"} - DOKKU_CONFIG_TYPE=${DOKKU_CONFIG_TYPE:="app"} - DOKKU_CONFIG_RESTART=${DOKKU_CONFIG_RESTART:=true} - - if [[ "$DOKKU_CONFIG_TYPE" = "app" ]]; then - if [[ -z $APP ]]; then - echo "Please specify an app to run the command on" >&2 && exit 1 - else - verify_app_name "$2" - fi - fi - export APP ENV_FILE DOKKU_CONFIG_TYPE DOKKU_CONFIG_RESTART -} - is_config_export() { for var in "$@"; do if [[ "$var" == "--export" ]]; then @@ -87,7 +58,7 @@ is_config_export() { case "$1" in config) - parse_config_args "$@" + config_parse_args "$@" config_create is_config_export "$@" && config_export "$DOKKU_CONFIG_TYPE" "$APP" && exit 0 @@ -109,7 +80,7 @@ case "$1" in ;; config:get) - parse_config_args "$@" + config_parse_args "$@" if [[ -z $3 ]]; then echo "Usage: dokku config:get APP KEY" @@ -128,7 +99,7 @@ case "$1" in ;; config:set) - parse_config_args "$@" + config_parse_args "$@" [[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}" if [[ -z "${*:3}" ]]; then @@ -181,7 +152,7 @@ ${var}" ;; config:unset) - parse_config_args "$@" + config_parse_args "$@" [[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}" if [[ -z $3 ]]; then diff --git a/plugins/config/functions b/plugins/config/functions index 8c2b54841..d21742bd8 100644 --- a/plugins/config/functions +++ b/plugins/config/functions @@ -15,3 +15,33 @@ config_export() { echo "$VARS" | awk '{print "export " $0}' return 0 } + +config_parse_args() { + case "$2" in + --global) + ENV_FILE="$DOKKU_ROOT/ENV" + DOKKU_CONFIG_TYPE="global" + DOKKU_CONFIG_RESTART=false + ;; + --no-restart) + APP="$3" + ENV_FILE="$DOKKU_ROOT/$APP/ENV" + DOKKU_CONFIG_RESTART=false + DOKKU_CONFIG_TYPE="app" + set -- "${@:1:1}" "${@:3}" + esac + + APP=${APP:="$2"} + ENV_FILE=${ENV_FILE:="$DOKKU_ROOT/$APP/ENV"} + DOKKU_CONFIG_TYPE=${DOKKU_CONFIG_TYPE:="app"} + DOKKU_CONFIG_RESTART=${DOKKU_CONFIG_RESTART:=true} + + if [[ "$DOKKU_CONFIG_TYPE" = "app" ]]; then + if [[ -z $APP ]]; then + echo "Please specify an app to run the command on" >&2 && exit 1 + else + verify_app_name "$2" + fi + fi + export APP ENV_FILE DOKKU_CONFIG_TYPE DOKKU_CONFIG_RESTART +}