diff options
author | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-04-24 09:17:30 -0400 |
---|---|---|
committer | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-04-24 09:17:30 -0400 |
commit | f99c5dd2c488f132024b38aa71b0be18ab4b6fd3 (patch) | |
tree | f0acc8855a0a4c9ce609324c57f96dee25236524 | |
parent | bffe32411e8ded537c5615ea054b43b3f7334bcd (diff) | |
download | gana-f99c5dd2c488f132024b38aa71b0be18ab4b6fd3.tar.gz gana-f99c5dd2c488f132024b38aa71b0be18ab4b6fd3.zip |
add --help/--version support
* format.sh
(me, version): New vars.
<top-level>: Handle ‘--help’ on command line.
<top-level>: Likewise for ‘--version’.
(template): New var.
<top-level>: Use ‘recfmt -f’ and ‘$template’.
-rwxr-xr-x | format.sh | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1,2 +1,27 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | exec recfmt "`cat $1`" | 2 | ## |
3 | # Usage: format.sh TEMPLATE | ||
4 | # | ||
5 | # This runs recfmt w/ template file TEMPLATE on stdin, writing to stdout. | ||
6 | ## | ||
7 | me=$(basename $0) | ||
8 | |||
9 | version='1.1' | ||
10 | # 1.1 -- add --help/--version support | ||
11 | # 1.0 -- initial release | ||
12 | |||
13 | if [ x"$1" = x--help ] ; then | ||
14 | sed '/^##/,/^##/!d;/^##/d;s/^# //g;s/^#$//g' $0 | ||
15 | exit 0 | ||
16 | fi | ||
17 | |||
18 | if [ x"$1" = x--version ] ; then | ||
19 | echo $me '(gana)' $version | ||
20 | exit 0 | ||
21 | fi | ||
22 | |||
23 | template="$1" | ||
24 | |||
25 | exec recfmt -f "$template" | ||
26 | |||
27 | # format.sh ends here | ||