]> git.tue.mpg.de Git - gsu.git/commitdiff
com_help(): Improve formating of command/description list
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 2 Aug 2023 21:09:11 +0000 (23:09 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 20 Aug 2023 14:29:24 +0000 (16:29 +0200)
The help output, which consists of the subcommand name and the
one-line description, is formatted incorrectly if the name of one
or more subcommands exceeds 16 characters. Pre-compute the maximal
length of the command names upfront to fix that.

subcommand

index 817486dba0c43564701095b49f2069498da9ee6b..d37481cdbdccb5b62268d3b788de84b61a2ab347 100644 (file)
@@ -684,7 +684,21 @@ com_help()
                                y/\n/'"$tab"'/
 
                                # and print the sucker
-                               p'
+                               p
+                       ' | {
+                               local -a cmds=() descs=()
+                               local -i i maxlen=1
+                               local cmd desc
+                               while read cmd desc; do
+                                       ((maxlen < ${#cmd})) && maxlen=${#cmd}
+                                       cmds[${#cmds[@]}]=$cmd
+                                       descs[${#descs[@]}]=$desc
+                               done
+                               for ((i = 0; i < ${#cmds[@]}; i++)); do
+                                       printf '%-*s %s\n' $maxlen ${cmds[$i]} \
+                                               "${descs[$i]}"
+                               done
+                       }
                printf "\n# Try %s help <command> for info on <command>, or %s help -a to see\n" \
                        "$gsu_name" "$gsu_name"
                printf '# also the subcommands which are automatically generated by gsu.\n'