Move config arg parsing into config/functions
This commit is contained in:
1 parent
e08f02aca7
commit
99f1f1b6d3
2 files changed
+35
-34
No files matched your search
+5
-34
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_PATH/common/functions"
|
source "$PLUGIN_PATH/common/functions"
|
||||||
|
source "$PLUGIN_PATH/config/functions"
|
||||||
|
|
||||||
config_create () {
|
config_create () {
|
||||||
[ -f $ENV_FILE ] || {
|
[ -f $ENV_FILE ] || {
|
||||||
@@ -46,36 +47,6 @@ config_write() {
|
|||||||
rm -f $ENV_FILE_TEMP
|
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() {
|
is_config_export() {
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
if [[ "$var" == "--export" ]]; then
|
if [[ "$var" == "--export" ]]; then
|
||||||
@@ -87,7 +58,7 @@ is_config_export() {
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
config)
|
config)
|
||||||
parse_config_args "$@"
|
config_parse_args "$@"
|
||||||
config_create
|
config_create
|
||||||
is_config_export "$@" && config_export "$DOKKU_CONFIG_TYPE" "$APP" && exit 0
|
is_config_export "$@" && config_export "$DOKKU_CONFIG_TYPE" "$APP" && exit 0
|
||||||
|
|
||||||
@@ -109,7 +80,7 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
config:get)
|
config:get)
|
||||||
parse_config_args "$@"
|
config_parse_args "$@"
|
||||||
|
|
||||||
if [[ -z $3 ]]; then
|
if [[ -z $3 ]]; then
|
||||||
echo "Usage: dokku config:get APP KEY"
|
echo "Usage: dokku config:get APP KEY"
|
||||||
@@ -128,7 +99,7 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
config:set)
|
config:set)
|
||||||
parse_config_args "$@"
|
config_parse_args "$@"
|
||||||
[[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}"
|
[[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}"
|
||||||
|
|
||||||
if [[ -z "${*:3}" ]]; then
|
if [[ -z "${*:3}" ]]; then
|
||||||
@@ -181,7 +152,7 @@ ${var}"
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
config:unset)
|
config:unset)
|
||||||
parse_config_args "$@"
|
config_parse_args "$@"
|
||||||
[[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}"
|
[[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}"
|
||||||
|
|
||||||
if [[ -z $3 ]]; then
|
if [[ -z $3 ]]; then
|
||||||
|
|||||||
@@ -15,3 +15,33 @@ config_export() {
|
|||||||
echo "$VARS" | awk '{print "export " $0}'
|
echo "$VARS" | awk '{print "export " $0}'
|
||||||
return 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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user