diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-04-15 17:06:52 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-04-15 17:19:47 -0400 |
commit | bd1d554a35b543afa5a79dd483583bf2aad9cf47 (patch) | |
tree | 4c93824f367f0d0f95ce4231ee563ed8a865317e /src/lib/messages.sh | |
parent | 080d2decb7e3aae1917de9d8a7d5089d74833d65 (diff) |
libremessages:flag: Fix several things (also librexgettext)
- Fix a bug where it panicked if given an odd number of sub-headings.
- Document the the ability to include sub-headings.
- Fix librexgettext's handling of it. It only worked correctly for times
when it was only called once in a program, or when it was only ever
called with exactly one flag/description pair (and no headings).
Diffstat (limited to 'src/lib/messages.sh')
-rw-r--r-- | src/lib/messages.sh | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/messages.sh b/src/lib/messages.sh index 4b4897e..0125003 100644 --- a/src/lib/messages.sh +++ b/src/lib/messages.sh @@ -92,14 +92,15 @@ bullet() { printf -- "$mesg" "$@" | fmt -u -w 71 | sed -e '1s/^/ - /' -e '2,$s/^/ /' } -# Usage: flag FLAG DESCRIPTION [FLAG2 DESCRIPTION2...] +# Usage: flag [FLAG DESCRIPTION|HEADING:]... # # Print a flag and description formatted for --help text. # # ex: flag '-C <FILE>' 'Use this file instead of pacman.conf' # -# The description is fed through gettext, the flag is not, so if part -# of the flag needs to be translated, you must do that yourself: +# The descriptions and headings are fed through gettext, the flags ar +# not, so if part of a flag needs to be translated, you must do that +# yourself: # # ex: flag "-C <$(_ FILE)>" 'Use this file instead of pacman.conf' # @@ -107,8 +108,10 @@ bullet() { # crazy-long, feel free, it is reflowed/wrapped the same way as prose # and bullet. If you pass in multiple flag/description pairs at once, # the descriptions are all alligned together. +# +# A heading MUST end with a colon (':'), this is how it knows that it +# is a heading. Similarly, a flag MUST NOT end with a colon. flag() { - [[ $# == $(($#/2*2)) ]] || panic local args=("$@") declare -i flaglen=0 @@ -147,6 +150,7 @@ flag() { printf -- ' %s\n' "$(_ "$1")" shift else + [[ $# -gt 1 ]] || panic local flag=$1 local desc="$(_ "$(whitespace_collapse <<<"$2")")" shift 2 |