Quellcode durchsuchen

Merge usage and help to --help

Be nicer to people who get help by trial and error.
Alois Mahdal vor 8 Jahren
Ursprung
Commit
b800648186
2 geänderte Dateien mit 28 neuen und 22 gelöschten Zeilen
  1. 16
    19
      src/shellfu/saturnin.sh
  2. 12
    3
      tests/cli/oracle/usage.stderr

+ 16
- 19
src/shellfu/saturnin.sh Datei anzeigen

142
 }
142
 }
143
 
143
 
144
 saturnin__help() {
144
 saturnin__help() {
145
-    #
146
-    # Print simple help message (basically just list of commands)
147
-    #
148
-    {
149
-        echo "built-in commands:"
150
-        echo "    conf"
151
-        echo "    help"
152
-        echo ""
153
-        echo "installed commands:"
154
-        saturnin__lssc \
155
-          | sed -e 's/^/    /'
156
-    } | mkhelp -E -f -
157
-    return "$EXIT_OK"
145
+    saturnin__usage --wanted
158
 }
146
 }
159
 
147
 
160
 saturnin__lssc() {
148
 saturnin__lssc() {
161
     #
149
     #
162
     # List subcommands
150
     # List subcommands
163
     #
151
     #
152
+    echo conf
164
     find "$SATURNIN_LIBEXEC" \
153
     find "$SATURNIN_LIBEXEC" \
165
         -mindepth 1 \
154
         -mindepth 1 \
166
         -maxdepth 1 \
155
         -maxdepth 1 \
174
     while true; do case $1 in
163
     while true; do case $1 in
175
         -d|--debug)     export PRETTY_DEBUG=true; shift   ;;
164
         -d|--debug)     export PRETTY_DEBUG=true; shift   ;;
176
         -v|--verbose)   export PRETTY_VERBOSE=true; shift ;;
165
         -v|--verbose)   export PRETTY_VERBOSE=true; shift ;;
166
+        -h|--help)      saturnin__help; exit              ;;
177
         --version)      saturnin__version; exit            ;;
167
         --version)      saturnin__version; exit            ;;
178
         --version-semver) saturnin__get app-version ;;
168
         --version-semver) saturnin__get app-version ;;
179
         --saturnin-get-*) saturnin__get "$1" ;;
169
         --saturnin-get-*) saturnin__get "$1" ;;
187
     debug -v SHELLFU_PATH SATURNIN_LIBEXEC SATURNIN_CONF_PATH
177
     debug -v SHELLFU_PATH SATURNIN_LIBEXEC SATURNIN_CONF_PATH
188
     case "$subcommand" in
178
     case "$subcommand" in
189
         conf)               saturnin__conf "$@" ;;
179
         conf)               saturnin__conf "$@" ;;
190
-        help)               saturnin__help ;;
191
         _ls_subcommands)    saturnin__lssc ;;
180
         _ls_subcommands)    saturnin__lssc ;;
192
         _lsfun)             shellfu-get lsfun ;;
181
         _lsfun)             shellfu-get lsfun ;;
193
         _lsmod)             shellfu-get lsmod ;;
182
         _lsmod)             shellfu-get lsmod ;;
255
     debug "\$*='$*'"
244
     debug "\$*='$*'"
256
     test -x "$binpath" || {
245
     test -x "$binpath" || {
257
         warn "invalid sub-command: $subcommand"
246
         warn "invalid sub-command: $subcommand"
258
-        saturnin__help
259
-        return "$EXIT_USAGE"
247
+        saturnin__usage
260
     }
248
     }
261
     SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
249
     SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
262
 }
250
 }
263
 
251
 
264
 saturnin__usage() {
252
 saturnin__usage() {
265
-    mkusage "[-d|-v] command [args...]" \
266
-            "help" \
267
-            "--version"
253
+    local es_param      # exit-status related arguments
254
+    test "$1" == "--wanted" && es_param="-e 0"
255
+    #shellcheck disable=SC2086 disable=SC2046
256
+    mkusage $es_param                                       \
257
+            "[options] COMMAND [ARG...]"                    \
258
+        -o                                                  \
259
+            "--debug    turn on debugging"                  \
260
+            "--help     show this help message and exit"    \
261
+            "--verbose  turn on verbosity"                  \
262
+            "--version  show version and exit"              \
263
+        -c                                                  \
264
+            $(saturnin__lssc)
268
 }
265
 }
269
 
266
 
270
 saturnin__version() {
267
 saturnin__version() {

+ 12
- 3
tests/cli/oracle/usage.stderr Datei anzeigen

1
 usage:
1
 usage:
2
-  satcmd [-d|-v] command [args...]
3
-  satcmd help
4
-  satcmd --version
2
+  satcmd [options] command [args...]
3
+
4
+options:
5
+  --debug    turn on debugging
6
+  --help     show this help message and exit
7
+  --verbose  turn on verbosity
8
+  --version  show version and exit
9
+
10
+commands:
11
+  conf
12
+  dump
13
+  echo