-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp
More file actions
executable file
·90 lines (72 loc) · 2.34 KB
/
help
File metadata and controls
executable file
·90 lines (72 loc) · 2.34 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
# shellcheck disable=SC2155
export SUBCOMMAND_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands"
fn-help() {
declare CMD="$1"
local cmd EXIT_CODE
if [[ "$CMD" == "help" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX:help" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX:default" ]]; then
fn-help-all "$@"
exit 0
fi
pushd "$SUBCOMMAND_ROOT" >/dev/null 2>&1
for cmd in *; do
if [[ "$CMD" == "${PLUGIN_COMMAND_PREFIX}:$cmd" ]]; then
"$SUBCOMMAND_ROOT/$cmd" "$@"
EXIT_CODE="$?"
exit "$EXIT_CODE"
fi
done
popd >/dev/null 2>&1
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
}
fn-help-all() {
local CMD="$1"
local plugin="$PLUGIN_COMMAND_PREFIX"
local lines=()
# Always expose a help entry
lines+=("${plugin}:help,Show help for the ${plugin} plugin")
# Collect subcommands and their descriptions
pushd "$SUBCOMMAND_ROOT" >/dev/null 2>&1
for sc in *; do
[[ -f "$sc" ]] || continue
[[ "$sc" == "default" ]] && continue
local file="$SUBCOMMAND_ROOT/$sc"
local desc=""
local line=""
# Try to extract: declare desc="..."
line="$(grep -m1 -E 'declare[[:space:]]+desc=' "$file" 2>/dev/null || true)"
if [[ -n "$line" ]]; then
desc="${line#*desc=}"
# Remove inline comments and CR (in case of Windows line endings)
desc="${desc%%#*}"
desc="${desc%$'\r'}"
# Trim whitespace
desc="${desc#"${desc%%[![:space:]]*}"}"
desc="${desc%"${desc##*[![:space:]]}"}"
# Strip surrounding quotes
desc="${desc%\"}"; desc="${desc#\"}"
desc="${desc%\'}"; desc="${desc#\'}"
fi
[[ -z "$desc" ]] && desc="(no description)"
lines+=("${plugin}:${sc},${desc}")
done
popd >/dev/null 2>&1
# When Dokku calls "help", it expects only "cmd,desc" lines
if [[ "$CMD" == "help" ]]; then
printf '%s\n' "${lines[@]}" | sort
return 0
fi
# Full help output (for dokku <plugin> / <plugin>:help / etc)
echo "Usage: dokku ${plugin}:<command> [args]"
echo ""
echo "Commands:"
if command -v column >/dev/null 2>&1; then
printf '%s\n' "${lines[@]}" | sort | column -c2 -t -s,
else
# Fallback if 'column' is not available
printf '%s\n' "${lines[@]}" | sort
fi
}