|
@@ -12,6 +12,11 @@ ffoo import exit
|
12
|
12
|
#
|
13
|
13
|
FFOO_PRETTY=${FFOO_PRETTY:-plain}
|
14
|
14
|
|
|
15
|
+#
|
|
16
|
+# Usage mode -- set to 'subcommand' to remove first dash
|
|
17
|
+#
|
|
18
|
+FFOO_PRETTY_USAGE=${FFOO_PRETTY_USAGE:-}
|
|
19
|
+
|
15
|
20
|
|
16
|
21
|
__ffoo_pretty__init() {
|
17
|
22
|
#
|
|
@@ -104,6 +109,12 @@ usage_is() {
|
104
|
109
|
#
|
105
|
110
|
# Use "--" to delimit end of arguments processed by usage_is.
|
106
|
111
|
#
|
|
112
|
+ # Setting FFOO_PRETTY_USAGE to 'subcommand' has effect that
|
|
113
|
+ # in each call, first hyphen in the script's "own" name is
|
|
114
|
+ # replaced by space; this is used for git-like sub-commands,
|
|
115
|
+ # where the actual binary name is e.g. "git-add" for
|
|
116
|
+ # "git add".
|
|
117
|
+ #
|
107
|
118
|
# Recommended usage is to define usage() in your script and
|
108
|
119
|
# use this in its body. That way you only need to define
|
109
|
120
|
# usage patterns once and skip to them from any place where
|
|
@@ -313,9 +324,14 @@ __echo_usage() {
|
313
|
324
|
#
|
314
|
325
|
# Print each argument as usage pattern
|
315
|
326
|
#
|
|
327
|
+ local self
|
|
328
|
+ case "$FFOO_PRETTY_USAGE" in
|
|
329
|
+ subcommand) self="${caller/-/ }" ;;
|
|
330
|
+ *) self="$caller" ;;
|
|
331
|
+ esac
|
316
|
332
|
local u
|
317
|
333
|
for u in "$@";
|
318
|
|
- do echo "usage: $caller $u"
|
|
334
|
+ do echo "usage: $self $u"
|
319
|
335
|
done
|
320
|
336
|
}
|
321
|
337
|
|