Browse Source

Add mkhelp for --help printing

Alois Mahdal 9 years ago
parent
commit
671790657f

+ 8
- 0
src/include/_pretty_color.sh View File

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
 _pretty__usage_is() {
48
 _pretty__usage_is() {
41
     echo -ne "$FFOO_PRETTY_COLOR_USAGE_IS"
49
     echo -ne "$FFOO_PRETTY_COLOR_USAGE_IS"
42
     while IFS= read line;
50
     while IFS= read line;

+ 6
- 0
src/include/_pretty_html.sh View File

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
 _pretty__usage_is() {
22
 _pretty__usage_is() {
17
     while IFS= read line;
23
     while IFS= read line;
18
     do echo "<p class='usage'>$line</p>"; done
24
     do echo "<p class='usage'>$line</p>"; done

+ 5
- 0
src/include/_pretty_plain.sh View File

11
     do echo "$line"; done
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
 _pretty__usage_is() {
19
 _pretty__usage_is() {
15
     while IFS= read line;
20
     while IFS= read line;
16
     do echo "$line"; done
21
     do echo "$line"; done

+ 46
- 1
src/include/pretty.sh View File

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
 think() {
176
 think() {
139
     #
177
     #
140
     # If verbose is on, think loud
178
     # If verbose is on, think loud
235
     frontend="$(_pretty__cut_stack '^_pretty__echo' | head -1 )"
273
     frontend="$(_pretty__cut_stack '^_pretty__echo' | head -1 )"
236
     caller="$(
274
     caller="$(
237
         _pretty__cut_stack \
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
             | head -1
277
             | head -1
240
     )"
278
     )"
241
     test "$frontend" == "main" && frontend=$(basename $0)
279
     test "$frontend" == "main" && frontend=$(basename $0)
254
     case $frontend in
292
     case $frontend in
255
         debug)    ;&
293
         debug)    ;&
256
         die)      ;&
294
         die)      ;&
295
+        mkhelp)   ;&
257
         think)    ;&
296
         think)    ;&
258
         usage_is) ;&
297
         usage_is) ;&
259
         warn)
298
         warn)
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
 _pretty__echo_usage() {
368
 _pretty__echo_usage() {
324
     #
369
     #
325
     # Print each argument as usage pattern
370
     # Print each argument as usage pattern

+ 5
- 0
tests/ffoo_api/oracle/functions.stdout View File

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