forked from SierraSoftworks/bash-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelp
executable file
·73 lines (58 loc) · 2.03 KB
/
help
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
#!/usr/bin/env bash
source $ROOT_DIR/app/.helper/system
ROOT_DIR=`dirname "$(_readlink -f $0)"`
CLI_ENTRYPOINT=`basename "$1"`
. "$ROOT_DIR/utils"
# If we don't have any additional help arguments, then show the app's
# header as well.
if [ $# == 0 ]; then
bcli_show_header "$ROOT_DIR/app"
fi
# Locate the correct level to display the helpfile for, either a directory
# with no further arguments, or a command file.
HELP_FILE="$ROOT_DIR/app/"
HELP_ARG_START=2
while [[ -d "$HELP_FILE" && $HELP_ARG_START -le $# ]]; do
HELP_FILE="$HELP_FILE/${!HELP_ARG_START}"
HELP_ARG_START=$(($HELP_ARG_START+1))
done
# If we've got a directory's helpfile to show, then print out the list of
# commands in that directory along with its help content.
if [[ -d "$HELP_FILE" ]]; then
echo -e "${COLOR_GREEN}$CLI_ENTRYPOINT ${COLOR_CYAN}${@:2:$(($HELP_ARG_START-1))} ${COLOR_NORMAL}"
# If there's a help file available for this directory, then show it.
if [[ -f "$HELP_FILE/.help" ]]; then
cat "$HELP_FILE/.help"
echo ""
fi
echo ""
echo -e "${COLOR_MAGENTA}Commands${COLOR_NORMAL}"
echo ""
for file in $HELP_FILE/*; do
cmd=`basename "$file"`
# Don't show hidden files as available commands
if [[ "$cmd" != .* && "$cmd" != *.usage && "$cmd" != *.help ]]; then
echo -en "${COLOR_GREEN}$CLI_ENTRYPOINT ${COLOR_CYAN}${@:2:$(($HELP_ARG_START-1))} $cmd ${COLOR_NORMAL}"
if [[ -f "$file.usage" ]]; then
bcli_trim_whitespace "$(cat "$file.usage")"
echo ""
elif [[ -d "$file" ]]; then
echo -e "${COLOR_MAGENTA}...${COLOR_NORMAL}"
else
echo ""
fi
fi
done
exit 0
fi
echo -en "${COLOR_GREEN}$CLI_ENTRYPOINT ${COLOR_CYAN}${@:2:$(($HELP_ARG_START-1))} ${COLOR_NORMAL}"
if [[ -f "$HELP_FILE.usage" ]]; then
bcli_trim_whitespace "$(cat "$HELP_FILE.usage")"
echo ""
else
echo ""
fi
if [[ -f "$HELP_FILE.help" ]]; then
cat "$HELP_FILE.help"
echo ""
fi