Subject: Re: [PATCH v4 4/4] parse-options: properly align continued usage output

From: Junio C Hamano <[email-masked]>
Date: Sun, 12 Sep 2021 23:41:36 -0700

Ævar Arnfjörð Bjarmason  <[email-masked]> writes:

> Some commands such as "git stash" emit continued options output with
> e.g. "git stash -h", because usage_with_options_internal() prefixes
> with its own whitespace the resulting output wasn't properly
> aligned. Let's account for the added whitespace, which properly aligns
> the output.
>
> The "git stash" command has usage output with a N_() translation that
> legitimately stretches across multiple lines;
>
> 	N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
> 	   "          [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
>            [...]
>
> We'd like to have that output aligned with the length of the initial
> "git stash " output, but since usage_with_options_internal() adds its
> own whitespace prefixing we fell short, before this change we'd emit:
>
>     $ git stash -h
>     usage: git stash list [<options>]
>        or: git stash show [<options>] [<stash>]
>        [...]
>        or: git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
>               [-u|--include-untracked] [-a|--all] [-m|--message <message>]
>               [...]
>
> Now we'll properly emit aligned output.  I.e. the last four lines
> above will instead be (a whitespace-only change to the above):
>
>        [...]
>        or: git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
>                      [-u|--include-untracked] [-a|--all] [-m|--message <message>]
>                      [...]
>
> We could also go for an approach where we have the caller support no
> padding of their own, i.e. (same as the first example, except for the
> padding on the second line):
>
> 	N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
> 	   "[-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
>            [...]
>
> But to do that we'll need to find the length of "git stash". We can
> discover that from the "cmd" in the "struct cmd_struct", but there
> might cases with sub-commands or "git" itself taking arguments that

A "be" is missing here.

> would make that non-trivial.
>
> Even if it was I still think this approach is better, because this way

"was" -> "were,", I think.

Even though this step has quite a lot of comment strings meant for
human consumption, I didn't hunt for grammos and typos and only
looked at the code.  Somebody else may want to proof-read it.

The new code looked OK.  Do we want to have some new test in
t/helper/test-*.c with fixed "command help string"?

Thanks.