summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-10-12 09:53:48 (EDT)
committer P. J. McDermott <pjm@nac.net>2013-10-12 09:53:48 (EDT)
commit14510e8e8055636a93a8cf3c302f89bd464d3ea3 (patch)
treef6e5ecc110ce07cf238bcc8c95b1fcf0ba1b1196
parent19436dbe4282d50606cedbbc89d6d10ec56c4937 (diff)
Print option arguments in help output.
-rw-r--r--lib/cmd.sh30
-rw-r--r--lib/cmd/help.sh4
-rw-r--r--locale/en_US/pro_archman.sh9
3 files changed, 37 insertions, 6 deletions
diff --git a/lib/cmd.sh b/lib/cmd.sh
index fa9b1ad..a14eb00 100644
--- a/lib/cmd.sh
+++ b/lib/cmd.sh
@@ -37,6 +37,36 @@ load_cmds()
done
}
+print_opt_summaries()
+{
+ local optstring="${1}"
+ local padding=
+ local opt=
+ local opt_out=
+ local summary=
+
+ padding="$(printf '%24s' '')"
+ for opt in $(printf '%s' "${optstring}" | sed 's/\([a-zA-Z0-9]\)/ \1/g')
+ do
+ if [ ${#opt} -eq 1 ]; then
+ # No argument expected.
+ opt_out="-${opt}"
+ else
+ # Argument expected.
+ opt="${opt%?}"
+ opt_out="-${opt} $(get_msg "opt_${opt}_arg")"
+ fi
+ if [ ${#opt_out} -gt 20 ]; then
+ printf ' %s\n%24s' "${opt_out}" ''
+ else
+ printf ' %-20s ' "${opt_out}"
+ fi
+ summary="$(get_msg "opt_${opt}_summary")"
+ printf '%s\n' "${summary}" | fold -s -w 56 | \
+ sed "2,\$s/^/${padding}/;"
+ done
+}
+
print_cmd_summaries()
{
local padding=
diff --git a/lib/cmd/help.sh b/lib/cmd/help.sh
index 733e9ed..e186663 100644
--- a/lib/cmd/help.sh
+++ b/lib/cmd/help.sh
@@ -33,9 +33,7 @@ cmd_help_main()
printf "$(get_msg 'cmd_help_head')\n\n" "${0}"
printf "$(get_msg 'cmd_help_opts_head')\n"
- for opt in h V b; do
- printf ' -%c %s\n' "${opt}" "$(get_msg "cmd_help_opt_${opt}")"
- done
+ print_opt_summaries 'hVb:'
printf '\n'
printf "$(get_msg 'cmd_help_summary_head')\n"
diff --git a/locale/en_US/pro_archman.sh b/locale/en_US/pro_archman.sh
index 512369e..3c43120 100644
--- a/locale/en_US/pro_archman.sh
+++ b/locale/en_US/pro_archman.sh
@@ -20,6 +20,12 @@
# src/pro-archman.sh
msg_pro_archman_lock_fail='The archive is locked by another process'
+# Options
+msg_pro_archman_opt_h_summary='print this help message'
+msg_pro_archman_opt_V_summary='print version information'
+msg_pro_archman_opt_b_summary='set archive base directory to <base-dir>'
+msg_pro_archman_opt_b_arg='<base-dir>'
+
# lib/cmd.sh
msg_pro_archman_cmd_not_found='Command "%s" not found'
msg_pro_archman_cmd_usage='Usage: %s [<option> ...] %s %s'
@@ -27,9 +33,6 @@ msg_pro_archman_cmd_usage='Usage: %s [<option> ...] %s %s'
# lib/cmd/help.sh
msg_pro_archman_cmd_help_head='Usage: %s [<option> ...] <command>'
msg_pro_archman_cmd_help_opts_head='Options:'
-msg_pro_archman_cmd_help_opt_h='print this help message'
-msg_pro_archman_cmd_help_opt_V='print version information'
-msg_pro_archman_cmd_help_opt_b='archive base directory'
msg_pro_archman_cmd_help_summary_head='Commands:'
msg_pro_archman_cmd_help_summary='print this help message'
msg_pro_archman_cmd_help_usage='[<command>]'