git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 1, 2022, 09:23 UTC
Message-ID
<220401.86y20pnofb.gmgdl@evledraar.gmail.com>
In-Reply-To
<xmqqsfqx28dv.fsf@gitster.g>
On Thu, Mar 31 2022, Junio C Hamano wrote:
Show 20 quoted lines
> Garrit Franke <garrit@slashdev.space> 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.
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 11 in “cli: add -v and -h shorthands”
  1. cli: add -v and -h shorthandsGarrit Franke, Mar 30, 2022
  2. Junio C HamanoMar 30, 2022
  3. Garrit FrankeMar 30, 2022
  4. Ævar Arnfjörð BjarmasonMar 31, 2022
  5. Garrit FrankeMar 31, 2022
  6. Junio C HamanoMar 31, 2022
  7. Ævar Arnfjörð BjarmasonApr 1, 2022
  8. Junio C HamanoApr 1, 2022
  9. Garrit FrankeApr 4, 2022
  10. Junio C HamanoApr 4, 2022
  11. cli: add -v and -h shorthandsGarrit Franke, Mar 31, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.