]> git.ipfire.org Git - thirdparty/git.git/commit
short help: allow a gap smaller than USAGE_GAP
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Jul 2023 22:58:00 +0000 (15:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Jul 2023 23:39:02 +0000 (16:39 -0700)
commitc512643e67d33673933fa3d245be28b08b974755
tree3ebc7c3fe5f1c07c3bc8138c99420f1acbad4d4c
parentd86a8f386d89edaffec63a626f5226c9f39f5027
short help: allow a gap smaller than USAGE_GAP

The parse-options API responds to "git cmd -h" by listing the option
flag (padded to the USAGE_OPTS_WIDTH column), followed by USAGE_GAP
(set to 2) whitespaces, followed by the help text.  If the flags
part does not fit within the USAGE_OPTS_WIDTH, the help text is given
on its own line.  Imagine that "@" below depicts the USAGE_OPTS_WIDTH'th
column, and "#" are for the usage help text, the output may look
like this:

    @@@@@@@@@@@@@  ########################################
    -f    description of the flag '-f' comes here
    --short=<num>  description of the flag '--short'
    --very-long-option=<number>
                   description of the flag '--very-long-option'

This is all good and nice in principle, but it becomes awkward when
the flags part is just one column over the limit and forces a line
break.  See the description of the "--almost" option below:

    @@@@@@@@@@@@@  ########################################
    -f    description of the flag '-f' comes here
    --short=<num>  description of the flag '--short'
    --almost=<num>
                   description of the flag '--almost'
    --very-long-option=<number>
                   description of the flag '--very-long-option'

If we allow shrinking the gap to a single whitespace only in such a
case, we would instead get:

    @@@@@@@@@@@@@  ########################################
    -f    description of the flag '-f' comes here
    --short=<num>  description of the flag '--short'
    --almost=<num> description of the flag '--almost'
    --very-long-option=<number>
                   description of the flag '--very-long-option'

and the boundary between the flags and their descriptions does not
become any harder to see, while saving precious vertical screen real
estate.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c
t/t0040-parse-options.sh