From bd1d554a35b543afa5a79dd483583bf2aad9cf47 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 15 Apr 2016 17:06:52 -0400 Subject: 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). --- src/lib/messages.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/lib/messages.sh') 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 ' '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 -- cgit v1.2.3-54-g00ecf