Skip to content

Commit d307a5b

Browse files
committed
Output error message when a command is not found. Closes #778
Plugins with commands will need to implement a catch-all command that exits with the `DOKKU_NOT_IMPLEMENTED_EXIT`` code (10). This signals to dokku that a given plugin has indeed not executed anything for a plugin (which may not always be the case). Using plugins that do not implement this pattern will result in those plugins silencing the error message.
1 parent 1e5a904 commit d307a5b

8 files changed

Lines changed: 88 additions & 1 deletion

File tree

‎docs/plugins.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,49 @@ If you create your own plugin:
2828
3. edit this page and add a link to it below!
2929
4. subscribe to the [dokku development blog](http://progrium.com) to be notified about API changes and releases
3030

31+
### Sample plugin
32+
33+
The below plugin is a dummy `dokku hello` plugin. If your plugin exposes commands, this is a good template for your `commands` file:
34+
35+
```bash
36+
#!/usr/bin/env bash
37+
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
38+
39+
case "$1" in
40+
hello)
41+
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
42+
[[ ! -d "$DOKKU_ROOT/$APP" ]] && echo "App $APP does not exist" && exit 1
43+
APP="$2";
44+
45+
echo "Hello $APP"
46+
;;
47+
48+
hello:world)
49+
echo "Hello world"
50+
;;
51+
52+
help)
53+
cat && cat<<EOF
54+
hello <app> Says "Hello <app>"
55+
hello:world Says "Hello world"
56+
EOF
57+
;;
58+
59+
*)
60+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
61+
;;
62+
63+
esac
64+
```
65+
66+
A few notes:
67+
68+
- You should always support `DOKKU_TRACE` as specified on the 2nd line of the plugin.
69+
- If your command requires that an application exists, ensure you check for it's existence in the manner prescribed above.
70+
- A `help` command is required, though it is allowed to be empty.
71+
- Commands *should* be namespaced.
72+
- As of 0.3.3, a catch-all should be implemented which exits with a `DOKKU_NOT_IMPLEMENTED_EXIT` code. This allows dokku to output a `command not found` message.
73+
3174
## Community plugins
3275

3376
Note: The following plugins have been supplied by our community and may not have been tested by dokku maintainers.

‎dokku‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export DOKKU_IMAGE=${DOKKU_IMAGE:="progrium/buildstep"}
66
export DOKKU_ROOT=${DOKKU_ROOT:="/home/dokku"}
77

88
export PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
9+
export DOKKU_NOT_IMPLEMENTED_EXIT=10
10+
export DOKKU_VALID_EXIT=0
911

1012
[[ -f $DOKKU_ROOT/dokkurc ]] && source $DOKKU_ROOT/dokkurc
1113

@@ -143,6 +145,9 @@ case "$1" in
143145
;;
144146

145147
help|'')
148+
echo "Usage: dokku COMMAND <app> [command-specific-options]"
149+
echo ""
150+
146151
cat<<EOF | pluginhook commands help | sort
147152
help Print the list of commands
148153
plugins Print active plugins
@@ -151,9 +156,24 @@ EOF
151156
;;
152157

153158
*)
159+
implemented=0
154160
for script in $(ls -d $PLUGIN_PATH/*/commands); do
155-
$script "$@"
161+
set +e; $script "$@" ; exit_code=$? ; set -e
162+
if [ "$exit_code" -eq "$DOKKU_NOT_IMPLEMENTED_EXIT" ]; then
163+
continue
164+
fi
165+
166+
implemented=1
167+
if [ "$exit_code" -ne "$DOKKU_VALID_EXIT" ]; then
168+
exit $exit_code
169+
fi
156170
done
171+
172+
if [ "$implemented" -eq 0 ]; then
173+
echo " ! \`$@\` is not a dokku command."
174+
echo " ! See \`dokku help\` for a list of available commands."
175+
exit 1
176+
fi
157177
;;
158178

159179
esac

‎plugins/00_dokku-standard/commands‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ case "$1" in
7373
EOF
7474
;;
7575

76+
*)
77+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
78+
;;
79+
7680
esac

‎plugins/apps/commands‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@ case "$1" in
7272
EOF
7373
;;
7474

75+
*)
76+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
77+
;;
78+
7579
esac

‎plugins/backup/commands‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,8 @@ case "$1" in
9292
EOF
9393
;;
9494

95+
*)
96+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
97+
;;
98+
9599
esac

‎plugins/config/commands‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,8 @@ ${var}"
184184
EOF
185185
;;
186186

187+
*)
188+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
189+
;;
190+
187191
esac

‎plugins/git/commands‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ EOF
5858
cat
5959
;;
6060

61+
*)
62+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
63+
;;
64+
6165
esac

‎plugins/nginx-vhosts/commands‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ case "$1" in
4141
EOF
4242
;;
4343

44+
*)
45+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
46+
;;
47+
4448
esac

0 commit comments

Comments
 (0)