summaryrefslogtreecommitdiffstats
path: root/lib/cmd.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cmd.sh')
-rw-r--r--lib/cmd.sh30
1 files changed, 30 insertions, 0 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=