From 04dbe31919f8909a10dddb2e0e5c8ca38221da14 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 23 Nov 2014 23:31:33 -0500 Subject: [PATCH] Unify the way in which all error messages are specified Other parts of dokku use one-liners where possible, so these parts should as well --- plugins/00_dokku-standard/commands | 27 +++++------------ plugins/apps/commands | 26 ++++------------ plugins/config/commands | 48 ++++++++---------------------- plugins/nginx-vhosts/commands | 25 ++++------------ 4 files changed, 29 insertions(+), 97 deletions(-) diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index e30fb6eb3..7fd4f9476 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -7,15 +7,9 @@ case "$1" in ;; logs) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER) @@ -30,15 +24,10 @@ case "$1" in ;; run) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; IMAGE="dokku/$APP" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi + shift 2 DOCKER_ARGS=$(: | pluginhook docker-args $APP) @@ -46,11 +35,9 @@ case "$1" in ;; url) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then echo $(< "$DOKKU_ROOT/$APP/URL") diff --git a/plugins/apps/commands b/plugins/apps/commands index 2c8367b39..2fed52a7e 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -8,35 +8,19 @@ case "$1" in ;; apps:create) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ -d "$DOKKU_ROOT/$APP" ]] && echo " ! Name is already taken" && exit 1 APP="$2" - if [[ -d "$DOKKU_ROOT/$APP" ]]; then - echo " ! Name is already taken" - exit 1 - fi mkdir -p "$DOKKU_ROOT/$APP" echo "Creating $APP... done" ;; apps:destroy) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 + [[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1 APP="$2"; IMAGE="dokku/$APP"; - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi - - if [[ "$APP" == "tls" ]]; then - echo "Unable to destroy tls directory" - exit 1 - fi echo " ! WARNING: Potentially Destructive Action" echo " ! This command will destroy $APP (including all add-ons)." diff --git a/plugins/config/commands b/plugins/config/commands index 0086a0ed4..90242f56c 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -62,21 +62,12 @@ config_write() { case "$1" in config) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi config_create - if [[ ! -s $ENV_FILE ]] ; then - echo "$APP has no config vars" - exit 1 - fi + [[ ! -s $ENV_FILE ]] && echo "$APP has no config vars" && exit 1 VARS=`cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | cut -d" " -f2-` @@ -92,15 +83,10 @@ case "$1" in ;; config:get) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi + if [[ -z $3 ]]; then echo "Usage: dokku config:get APP KEY" echo "Must specify KEY." @@ -118,15 +104,10 @@ case "$1" in ;; config:set) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi + if [[ -z "${*:3}" ]]; then echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]" echo "Must specify KEY and VALUE to set." @@ -171,15 +152,10 @@ ${var}" ;; config:unset) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi + if [[ -z $3 ]]; then echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]" echo "Must specify KEY to unset." diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 56e95920e..e2b4632ac 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -3,31 +3,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in nginx:import-ssl) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 + [[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1 APP="$2" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi - if [[ -t 0 ]]; then - echo "Tar archive containing server.crt and server.key expected on stdin" - exit 1 - fi TEMP_DIR=`mktemp -d` cd $TEMP_DIR tar xvf - <&0 - if [[ -f "$TEMP_DIR/server.crt" ]]; then - echo "Tar archive missing server.crt" - exit 1 - fi - if [[ -f "$TEMP_DIR/server.key" ]]; then - echo "Tar archive missing server.key" - exit 1 - fi + [[ -f "$TEMP_DIR/server.crt" ]] && echo "Tar archive missing server.crt" && exit 1 + [[ -f "$TEMP_DIR/server.key" ]] && echo "Tar archive missing server.key" && exit 1 mkdir -p "$DOKKU_ROOT/$APP/tls" mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt"