Subject: Re: [PATCH v2] cli: add -v and -h shorthands

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Fri, 01 Apr 2022 11:23:39 +0200

On Thu, Mar 31 2022, Junio C Hamano wrote:

> Garrit Franke <[email-masked]> writes:
>
>> On 31.03.22 02:07, Ævar Arnfjörð Bjarmason wrote:
>>
>>> I think this is a good trade-off in this case. I.e. -v and -h are
>>> commonly understood.
>>
>> An interesting observation I just made is that curl [0] uses both
>> "--verbose" and "--version" on the top level [1][2] including
>> shorthands. "-v" corresponds to "verbose", "-V" corresponds to
>> "version.
>>
>> Not that I'm a fan of this clutter, but it's a possible path to go
>> down if we actually needed a second shorthand using this letter.
>
> Do you mean you want to use "-V" for version, instead of the "-v"
> used in the patch, so that "-v" can be left for "--verbose"?
>
> I am not sure consistency with whom we are aiming for anymore with
> that mixed to the proposal X-<.

Maybe you've been convinced to accept -v and -h (I don't care much
either way, honestly), but if not I wonder if this alternate approach
would make everyone in this thread happy (or at least mostly so):

diff --git a/git.c b/git.c
index a25940d72e8..929faa12537 100644
--- a/git.c
+++ b/git.c
@@ -323,7 +323,12 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 				exit(list_cmds(cmd));
 			}
 		} else {
-			fprintf(stderr, _("unknown option: %s\n"), cmd);
+			if (!strcmp(cmd, "-h"))
+				fprintf(stderr, _("unknown option: %s, did you mean --help?\n"), cmd);
+			else if (!strcmp(cmd, "-v"))
+				fprintf(stderr, _("unknown option: %s, did you mean --version?\n"), cmd);
+			else
+				fprintf(stderr, _("unknown option: %s\n"), cmd);
 			usage(git_usage_string);
 		}

(Better to pass those as a parameter to the translation, but it's just a
throwaway demo patch for discussion)

I.e. we could help the user in these cases by suggesting that they may
have meant --help or --version, while still leaving the door open to
using these short options for something else.

In git.c we don't use parse-options.c, but that might be a useful
addition for it in general. I.e. to allow an option to define a list of
known alternative (but not understood!) aliases for itself.

So for the cases where we're about to emit an error about -v or whatever
anyway, we could be a bit more helpful and suggest --version, even if we
didn't want to define that as a short option for whatever reason.