summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-05-31 11:52:46 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-05-31 13:37:23 -0600
commit238d56a8dc7614813af3ed36bc6e5c51a6290c15 (patch)
tree171e85e689c9b5d3e35ef240ba7d15da7af6b255
parenta608070d29143f11826725ae0261bf0dcd902bc2 (diff)
libremessages:flag: support sub-headings in the list of flags.
This changes libremessages:flag to treat would-be flagnames ending with ':' specially--as a sub-heading in the list of flags. The next argument is taken to be the next flag, not a description.
-rwxr-xr-xsrc/lib/libremessages37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/lib/libremessages b/src/lib/libremessages
index 151674b..528d9b6 100755
--- a/src/lib/libremessages
+++ b/src/lib/libremessages
@@ -110,16 +110,20 @@ bullet() {
# the descriptions are all alligned together.
flag() {
[[ $# == $(($#/2*2)) ]] || panic
-
local args=("$@")
+
declare -i flaglen=0
- declare -i i=0
- while [[ $i -lt $# ]]; do
- if [[ ${#args[i]} -gt $flaglen ]]; then
- flaglen=${#args[$i]}
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == *: ]]; then
+ shift 1
+ else
+ if [[ ${#1} -gt $flaglen ]]; then
+ flaglen=${#1}
+ fi
+ shift 2
fi
- i+=2
done
+ set -- "${args[@]}"
# Unless the $flaglen is extra-wide, the $desc should start at
# column 16 (that is two literal-tabs). If $flaglen is wide,
@@ -140,14 +144,19 @@ flag() {
printf -v fmt1 " %-${indent}s %%s\n" ''
while [[ $# -gt 0 ]]; do
- local flag=$1
- local desc="$(_ "$(whitespace_collapse <<<"$2")")"
- shift 2
-
- local lines
- IFS=$'\n' lines=($(fmt -u -w $((71-indent)) <<<"$desc"))
- printf -- "$fmt2" "$flag" "${lines[0]}"
- [[ ${#lines[@]} -lt 2 ]] || printf -- "$fmt1" "${lines[@]:1}"
+ if [[ $1 == *: ]]; then
+ printf -- ' %s\n' "$(_ "$1")"
+ shift
+ else
+ local flag=$1
+ local desc="$(_ "$(whitespace_collapse <<<"$2")")"
+ shift 2
+
+ local lines
+ IFS=$'\n' lines=($(fmt -u -w $((71-indent)) <<<"$desc"))
+ printf -- "$fmt2" "$flag" "${lines[0]}"
+ [[ ${#lines[@]} -lt 2 ]] || printf -- "$fmt1" "${lines[@]:1}"
+ fi
done
}