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

Re: [PATCH] parse-options: print "fatal:" before usage_msg_opt()

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 14, 2016, 17:57 UTC
Message-ID
<xmqqr35axujg.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161214151009.4wdzjb44f6aki5ug@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 28 quoted lines
> Programs may use usage_msg_opt() to print a brief message
> followed by the program usage, and then exit. The message
> isn't prefixed at all, though, so it doesn't match our usual
> error output and is easy to overlook:
>
>     $ git clone 1 2 3
>     Too many arguments.
>
>     usage: git clone [<options>] [--] <repo> [<dir>]
>
>     -v, --verbose         be more verbose
>     -q, --quiet           be more quiet
>     --progress            force progress reporting
>     -n, --no-checkout     don't create a checkout
>     --bare                create a bare repository
>     [...and so on for another 31 lines...]
>
> It looks especially bad when the message starts with an
> option, like:
>
>     $ git replace -e
>     -e needs exactly one argument
>
>     usage: git replace [-f] <object> <replacement>
>        or: git replace [-f] --edit <object>
>     [...etc...]
>
> Let's put our usual "fatal:" prefix in front of it.

I briefly wondered if any caller uses this in a non-fatal situation, but usage_with_options() always dies, so this looks like the right thing to do. Thanks.

Show 23 quoted lines
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Some of the message in git-clone could stand to be rewritten to match
> our usual style, too (no capitals, no trailing period), but that's
> obviously out of scope for this patch. I don't think this change makes
> them look any worse.
>
>  parse-options.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/parse-options.c b/parse-options.c
> index 312a85dbd..4fbe924a5 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -661,7 +661,7 @@ void NORETURN usage_msg_opt(const char *msg,
>  		   const char * const *usagestr,
>  		   const struct option *options)
>  {
> -	fprintf(stderr, "%s\n\n", msg);
> +	fprintf(stderr, "fatal: %s\n\n", msg);
>  	usage_with_options(usagestr, options);
>  }
Previous: Jeff KingNext: Duy Nguyen
Message 2 of 8 in “parse-options: print "fatal:" before usage_msg_opt()”
  1. parse-options: print "fatal:" before usage_msg_opt()Jeff King, Dec 14, 2016
  2. Junio C HamanoDec 14, 2016
  3. Duy NguyenDec 19, 2016
  4. Jeff KingDec 19, 2016
  5. Duy NguyenDec 19, 2016
  6. Jeff KingDec 19, 2016
  7. Duy NguyenDec 19, 2016
  8. Jeff KingDec 19, 2016

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.