Skip to content

Commit 04dbe31

Browse files
committed
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
1 parent 56185fc commit 04dbe31

4 files changed

Lines changed: 29 additions & 97 deletions

File tree

‎plugins/00_dokku-standard/commands‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ case "$1" in
77
;;
88

99
logs)
10-
if [[ -z $2 ]]; then
11-
echo "Please specify an app to run the command on"
12-
exit 1
13-
fi
10+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
11+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
1412
APP="$2";
15-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
16-
echo "App $APP does not exist"
17-
exit 1
18-
fi
1913

2014
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
2115
CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER)
@@ -30,27 +24,20 @@ case "$1" in
3024
;;
3125

3226
run)
33-
if [[ -z $2 ]]; then
34-
echo "Please specify an app to run the command on"
35-
exit 1
36-
fi
27+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
28+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
3729
APP="$2"; IMAGE="dokku/$APP"
38-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
39-
echo "App $APP does not exist"
40-
exit 1
41-
fi
30+
4231
shift 2
4332

4433
DOCKER_ARGS=$(: | pluginhook docker-args $APP)
4534
docker run -i -t $DOCKER_ARGS $IMAGE /exec "$@"
4635
;;
4736

4837
url)
38+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
39+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
4940
APP="$2";
50-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
51-
echo "App $APP does not exist"
52-
exit 1
53-
fi
5441

5542
if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then
5643
echo $(< "$DOKKU_ROOT/$APP/URL")

‎plugins/apps/commands‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,19 @@ case "$1" in
88
;;
99

1010
apps:create)
11-
if [[ -z $2 ]]; then
12-
echo "Please specify an app to run the command on"
13-
exit 1
14-
fi
11+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
12+
[[ -d "$DOKKU_ROOT/$APP" ]] && echo " ! Name is already taken" && exit 1
1513
APP="$2"
16-
if [[ -d "$DOKKU_ROOT/$APP" ]]; then
17-
echo " ! Name is already taken"
18-
exit 1
19-
fi
2014

2115
mkdir -p "$DOKKU_ROOT/$APP"
2216
echo "Creating $APP... done"
2317
;;
2418

2519
apps:destroy)
26-
if [[ -z $2 ]]; then
27-
echo "Please specify an app to run the command on"
28-
exit 1
29-
fi
20+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
21+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
22+
[[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1
3023
APP="$2"; IMAGE="dokku/$APP";
31-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
32-
echo "App $APP does not exist"
33-
exit 1
34-
fi
35-
36-
if [[ "$APP" == "tls" ]]; then
37-
echo "Unable to destroy tls directory"
38-
exit 1
39-
fi
4024

4125
echo " ! WARNING: Potentially Destructive Action"
4226
echo " ! This command will destroy $APP (including all add-ons)."

‎plugins/config/commands‎

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,12 @@ config_write() {
6262

6363
case "$1" in
6464
config)
65-
if [[ -z $2 ]]; then
66-
echo "Please specify an app to run the command on"
67-
exit 1
68-
fi
65+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
66+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
6967
APP="$2"
70-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
71-
echo "App $APP does not exist"
72-
exit 1
73-
fi
7468

7569
config_create
76-
if [[ ! -s $ENV_FILE ]] ; then
77-
echo "$APP has no config vars"
78-
exit 1
79-
fi
70+
[[ ! -s $ENV_FILE ]] && echo "$APP has no config vars" && exit 1
8071

8172
VARS=`cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | cut -d" " -f2-`
8273

@@ -92,15 +83,10 @@ case "$1" in
9283
;;
9384

9485
config:get)
95-
if [[ -z $2 ]]; then
96-
echo "Please specify an app to run the command on"
97-
exit 1
98-
fi
86+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
87+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
9988
APP="$2"
100-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
101-
echo "App $APP does not exist"
102-
exit 1
103-
fi
89+
10490
if [[ -z $3 ]]; then
10591
echo "Usage: dokku config:get APP KEY"
10692
echo "Must specify KEY."
@@ -118,15 +104,10 @@ case "$1" in
118104
;;
119105

120106
config:set)
121-
if [[ -z $2 ]]; then
122-
echo "Please specify an app to run the command on"
123-
exit 1
124-
fi
107+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
108+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
125109
APP="$2"
126-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
127-
echo "App $APP does not exist"
128-
exit 1
129-
fi
110+
130111
if [[ -z "${*:3}" ]]; then
131112
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
132113
echo "Must specify KEY and VALUE to set."
@@ -171,15 +152,10 @@ ${var}"
171152
;;
172153

173154
config:unset)
174-
if [[ -z $2 ]]; then
175-
echo "Please specify an app to run the command on"
176-
exit 1
177-
fi
155+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
156+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
178157
APP="$2"
179-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
180-
echo "App $APP does not exist"
181-
exit 1
182-
fi
158+
183159
if [[ -z $3 ]]; then
184160
echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]"
185161
echo "Must specify KEY to unset."

‎plugins/nginx-vhosts/commands‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
33

44
case "$1" in
55
nginx:import-ssl)
6-
if [[ -z $2 ]]; then
7-
echo "Please specify an app to run the command on"
8-
exit 1
9-
fi
6+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
7+
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
8+
[[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1
109
APP="$2"
11-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
12-
echo "App $APP does not exist"
13-
exit 1
14-
fi
15-
if [[ -t 0 ]]; then
16-
echo "Tar archive containing server.crt and server.key expected on stdin"
17-
exit 1
18-
fi
1910

2011
TEMP_DIR=`mktemp -d`
2112
cd $TEMP_DIR
2213
tar xvf - <&0
23-
if [[ -f "$TEMP_DIR/server.crt" ]]; then
24-
echo "Tar archive missing server.crt"
25-
exit 1
26-
fi
27-
if [[ -f "$TEMP_DIR/server.key" ]]; then
28-
echo "Tar archive missing server.key"
29-
exit 1
30-
fi
14+
[[ -f "$TEMP_DIR/server.crt" ]] && echo "Tar archive missing server.crt" && exit 1
15+
[[ -f "$TEMP_DIR/server.key" ]] && echo "Tar archive missing server.key" && exit 1
3116

3217
mkdir -p "$DOKKU_ROOT/$APP/tls"
3318
mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt"

0 commit comments

Comments
 (0)