Skip to content

Commit 11f6cdb

Browse files
committed
improve help
1 parent ffbaccd commit 11f6cdb

3 files changed

Lines changed: 46 additions & 33 deletions

File tree

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ FROM mcr.microsoft.com/devcontainers/php:8.3
44
RUN sed -i 's/^UMASK\s*022/UMASK 002/' /etc/login.defs
55
RUN usermod -aG www-data vscode
66

7+
# Add glow for formatting command usage output (and because it's just nice)
8+
sudo mkdir -p /etc/apt/keyrings
9+
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
10+
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
11+
712
# Install MariaDB and Redis and PHP (incl Apache) and Cypress dependencies
813
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
914
&& apt-get install -y libpng-dev libzip-dev libicu-dev \
@@ -14,7 +19,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
1419
&& docker-php-ext-enable redis zip \
1520
&& apt-get install -y mariadb-client redis-tools \
1621
&& apt-get install -y npm libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb \
17-
&& apt-get install -y dnsutils pv \
22+
&& apt-get install -y dnsutils glow pv \
1823
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
1924

2025
# Configure PHP, make memory_limit and upload_max_filesize match Pantheon

local/etc/uceap.d/help.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function help() {
2+
if [ $# -eq 1 ]; then
3+
command="$1"
4+
func=("${command//-/_}")
5+
if [[ " ${funcs[@]} " =~ " ${func} " ]]; then
6+
help="_${func}_help"
7+
echo "${!help}" | glow
8+
else
9+
echo "[error] Unknown command: $func"
10+
_help | glow
11+
fi
12+
else
13+
_help | glow
14+
fi
15+
}
16+
17+
function _help() {
18+
echo 'Available commands:'
19+
echo
20+
for func in "${funcs[@]}"; do
21+
command=("${func//_/-}")
22+
desc="_${func}_desc"
23+
echo "- **$command**: ${!desc}"
24+
echo
25+
done
26+
echo
27+
echo 'Please run **uceap \<command\>** to execute a command.'
28+
echo 'Please run **uceap help \<command\>** to see the help for a command.'
29+
}
30+
_help_desc='Displays help for `uceap` commands'
31+
_help_help='
32+
# Usage
33+
34+
``` sh
35+
uceap help
36+
uceap help <command>
37+
```
38+
'

local/etc/uceap.sh

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,12 @@ if [ -d $source_dir/uceap.d ]; then
88
done
99
fi
1010
unset func
11-
1211
funcs=($(typeset -F | cut -d' ' -f3 | grep -vE '^_'))
1312

14-
function uceap_help() {
15-
echo "Available commands:"
16-
echo
17-
for func in "${funcs[@]}"; do
18-
command=("${func//_/-}")
19-
desc="_${func}_desc"
20-
echo " $command: ${!desc}"
21-
echo
22-
done
23-
echo
24-
echo "Please run 'uceap <command>' to execute a command."
25-
echo "Please run 'uceap help <command>' to see the help for a command."
26-
}
27-
2813
function uceap() {
2914
if [ $# -eq 0 ]; then
30-
uceap_help
15+
help
3116
return 0
32-
fi
33-
if [ "$1" == "help" ]; then
34-
if [ $# -eq 2 ]; then
35-
command="$2"
36-
func=("${command//-/_}")
37-
if [[ " ${funcs[@]} " =~ " ${func} " ]]; then
38-
help="_${func}_help"
39-
echo "${!help}"
40-
else
41-
echo "[error] Unknown command: $func"
42-
uceap_help
43-
fi
44-
else
45-
uceap_help
46-
fi
4717
else
4818
command="$1"
4919
func=("${command//-/_}")
@@ -52,7 +22,7 @@ function uceap() {
5222
eval "$func" "$@"
5323
else
5424
echo "[error] Unknown command: $func"
55-
uceap_help
25+
help
5626
fi
5727
fi
5828
}

0 commit comments

Comments
 (0)