ソースを参照

Add mkhelp for --help printing

Alois Mahdal 10 年 前
コミット
671790657f
共有5 個のファイルを変更した70 個の追加1 個の削除を含む
  1. 8
    0
      src/include/_pretty_color.sh
  2. 6
    0
      src/include/_pretty_html.sh
  3. 5
    0
      src/include/_pretty_plain.sh
  4. 46
    1
      src/include/pretty.sh
  5. 5
    0
      tests/ffoo_api/oracle/functions.stdout

+ 8
- 0
src/include/_pretty_color.sh ファイルの表示

@@ -37,6 +37,14 @@ _pretty__die() {
37 37
 }
38 38
 
39 39
 
40
+_pretty__mkhelp() {
41
+    echo -ne "$FFOO_PRETTY_COLOR_USAGE_IS"
42
+    while IFS= read line;
43
+    do echo -e "$line"; done
44
+    echo -ne "$FFOO_PRETTY_COLOR_OFF"
45
+}
46
+
47
+
40 48
 _pretty__usage_is() {
41 49
     echo -ne "$FFOO_PRETTY_COLOR_USAGE_IS"
42 50
     while IFS= read line;

+ 6
- 0
src/include/_pretty_html.sh ファイルの表示

@@ -13,6 +13,12 @@ _pretty__die() {
13 13
 }
14 14
 
15 15
 
16
+_pretty__mkhelp() {
17
+    while IFS= read line;
18
+    do echo "<p class='usage'>$line</p>"; done
19
+}
20
+
21
+
16 22
 _pretty__usage_is() {
17 23
     while IFS= read line;
18 24
     do echo "<p class='usage'>$line</p>"; done

+ 5
- 0
src/include/_pretty_plain.sh ファイルの表示

@@ -11,6 +11,11 @@ _pretty__die() {
11 11
     do echo "$line"; done
12 12
 }
13 13
 
14
+_pretty__mkhelp() {
15
+    while IFS= read line;
16
+    do echo "$line"; done
17
+}
18
+
14 19
 _pretty__usage_is() {
15 20
     while IFS= read line;
16 21
     do echo "$line"; done

+ 46
- 1
src/include/pretty.sh ファイルの表示

@@ -135,6 +135,44 @@ usage_is() {
135 135
 }
136 136
 
137 137
 
138
+mkhelp() {
139
+    #
140
+    # Echo out help text
141
+    #
142
+    #     mkhelp line...
143
+    #
144
+    # Each argument as a separate line.  This makes it easy to
145
+    # print out bigger amount of text and still keep your script
146
+    # relatively clean:
147
+    #
148
+    #     mkhelp  "line1" \
149
+    #             "line2" \
150
+    #             "line3" \
151
+    #             "line4"
152
+    #
153
+    # By default, will exit with status *FFOO_EXIT_OK*, you
154
+    # can use `-e STATUS` to specify other number.
155
+    #
156
+    # Use `-E` to prevent exiting; in that case, the status
157
+    # that would be fed to `exit` will be used as exit status
158
+    # of this function.
159
+    #
160
+    # Use "--" to delimit end of arguments processed by mkhelp
161
+    #
162
+    local es=$FFOO_EXIT_OK
163
+    local doexit=true
164
+    while true; do case "$1" in
165
+        -e) es="$2";            shift 2      ;;
166
+        -E) doexit=false;       shift        ;;
167
+        --)                     shift; break ;;
168
+        *)                      break        ;;
169
+    esac done
170
+    _pretty__echo -l "$@"
171
+    $doexit && exit "$es"
172
+    return "$es"
173
+}
174
+
175
+
138 176
 think() {
139 177
     #
140 178
     # If verbose is on, think loud
@@ -235,7 +273,7 @@ _pretty__echo() {
235 273
     frontend="$(_pretty__cut_stack '^_pretty__echo' | head -1 )"
236 274
     caller="$(
237 275
         _pretty__cut_stack \
238
-            '^_pretty_|^warn$|^debug_pipe$|^debug$|^die$|^usage$|^usage_is$|^think$' \
276
+            '^_pretty_|^warn$|^debug_pipe$|^debug$|^die$|^mkhelp$|^usage$|^usage_is$|^think$' \
239 277
             | head -1
240 278
     )"
241 279
     test "$frontend" == "main" && frontend=$(basename $0)
@@ -254,6 +292,7 @@ _pretty__echo() {
254 292
     case $frontend in
255 293
         debug)    ;&
256 294
         die)      ;&
295
+        mkhelp)   ;&
257 296
         think)    ;&
258 297
         usage_is) ;&
259 298
         warn)
@@ -320,6 +359,12 @@ _pretty__echo_trace() {
320 359
 }
321 360
 
322 361
 
362
+_pretty__echo_help() {
363
+    local oldverbose="$FFOO_VERBOSE"
364
+    think -l "$@"
365
+    FFOO_VERBOSE=$oldverbose
366
+}
367
+
323 368
 _pretty__echo_usage() {
324 369
     #
325 370
     # Print each argument as usage pattern

+ 5
- 0
tests/ffoo_api/oracle/functions.stdout ファイルの表示

@@ -1,16 +1,19 @@
1 1
 _pretty_color.__ffoo__pretty_color__init
2 2
 _pretty_color._pretty__debug
3 3
 _pretty_color._pretty__die
4
+_pretty_color._pretty__mkhelp
4 5
 _pretty_color._pretty__think
5 6
 _pretty_color._pretty__usage_is
6 7
 _pretty_color._pretty__warn
7 8
 _pretty_html._pretty__debug
8 9
 _pretty_html._pretty__die
10
+_pretty_html._pretty__mkhelp
9 11
 _pretty_html._pretty__think
10 12
 _pretty_html._pretty__usage_is
11 13
 _pretty_html._pretty__warn
12 14
 _pretty_plain._pretty__debug
13 15
 _pretty_plain._pretty__die
16
+_pretty_plain._pretty__mkhelp
14 17
 _pretty_plain._pretty__think
15 18
 _pretty_plain._pretty__usage_is
16 19
 _pretty_plain._pretty__warn
@@ -34,6 +37,7 @@ pretty._pretty__cut_stack
34 37
 pretty._pretty__echo
35 38
 pretty._pretty__echo_args
36 39
 pretty._pretty__echo_cmd
40
+pretty._pretty__echo_help
37 41
 pretty._pretty__echo_files
38 42
 pretty._pretty__echo_lines
39 43
 pretty._pretty__echo_trace
@@ -44,6 +48,7 @@ pretty.debug
44 48
 pretty.debug_pipe
45 49
 pretty.die
46 50
 pretty.echos
51
+pretty.mkhelp
47 52
 pretty.think
48 53
 pretty.usage_is
49 54
 pretty.warn