-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands
executable file
·47 lines (41 loc) · 1.4 KB
/
commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Halt on error and support tracing.
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# Figure out plugin name, because apparently that's an odd information for dokku to provide.
PLUGIN_NAME="$(basename "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")"
export PLUGIN_NAME
# Read configuration file.
# shellcheck source=commands
source "$PLUGIN_ENABLED_PATH/$PLUGIN_NAME/config"
# Save command and shift positional arguments.
COMMAND="$1"
shift 1
# Extract the subcommand that was issued.
case "$COMMAND" in
$PLUGIN_COMMAND_PREFIX)
SUBCOMMAND="default"
;;
help)
# Dokku has an alternate format for listing all commands and subcommands in one go.
# But since the API doesn't tell us which format was requested we have to figure
# it out from the command used to invoke dokku. i.e. Test if it had --all in it.
#
# shellcheck disable=SC2009
if ps -o command= $PPID | grep '\--all' >/dev/null 2>&1; then
SUBCOMMAND="help"
set -- "--no-usage" "$*"
else
SUBCOMMAND="about"
fi
;;
*)
SUBCOMMAND="${COMMAND#$PLUGIN_COMMAND_PREFIX:}"
;;
esac
# Find subcommand script and execute it.
SUBCOMMAND_FILE="$PLUGIN_ENABLED_PATH/$PLUGIN_NAME/subcommands/$SUBCOMMAND"
if [ -x "$SUBCOMMAND_FILE" ]; then
"$SUBCOMMAND_FILE" "$@"
else
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
fi