Bläddra i källkod

Merge usage and help to --help

Be nicer to people who get help by trial and error.
Alois Mahdal 8 år sedan
förälder
incheckning
b800648186
2 ändrade filer med 28 tillägg och 22 borttagningar
  1. 16
    19
      src/shellfu/saturnin.sh
  2. 12
    3
      tests/cli/oracle/usage.stderr

+ 16
- 19
src/shellfu/saturnin.sh Visa fil

@@ -142,25 +142,14 @@ saturnin__get() {
142 142
 }
143 143
 
144 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 148
 saturnin__lssc() {
161 149
     #
162 150
     # List subcommands
163 151
     #
152
+    echo conf
164 153
     find "$SATURNIN_LIBEXEC" \
165 154
         -mindepth 1 \
166 155
         -maxdepth 1 \
@@ -174,6 +163,7 @@ saturnin__main() {
174 163
     while true; do case $1 in
175 164
         -d|--debug)     export PRETTY_DEBUG=true; shift   ;;
176 165
         -v|--verbose)   export PRETTY_VERBOSE=true; shift ;;
166
+        -h|--help)      saturnin__help; exit              ;;
177 167
         --version)      saturnin__version; exit            ;;
178 168
         --version-semver) saturnin__get app-version ;;
179 169
         --saturnin-get-*) saturnin__get "$1" ;;
@@ -187,7 +177,6 @@ saturnin__main() {
187 177
     debug -v SHELLFU_PATH SATURNIN_LIBEXEC SATURNIN_CONF_PATH
188 178
     case "$subcommand" in
189 179
         conf)               saturnin__conf "$@" ;;
190
-        help)               saturnin__help ;;
191 180
         _ls_subcommands)    saturnin__lssc ;;
192 181
         _lsfun)             shellfu-get lsfun ;;
193 182
         _lsmod)             shellfu-get lsmod ;;
@@ -255,16 +244,24 @@ saturnin__runsc() {
255 244
     debug "\$*='$*'"
256 245
     test -x "$binpath" || {
257 246
         warn "invalid sub-command: $subcommand"
258
-        saturnin__help
259
-        return "$EXIT_USAGE"
247
+        saturnin__usage
260 248
     }
261 249
     SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
262 250
 }
263 251
 
264 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 267
 saturnin__version() {

+ 12
- 3
tests/cli/oracle/usage.stderr Visa fil

@@ -1,4 +1,13 @@
1 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