parse-options.c: fix documentation syntax of optional arguments
When an argument for an option is optional, short options don't need a space between the option and the argument, and long options need a "=". Otherwise, arguments are misinterpreted. Signed-off-by: Michele Ballabio <barra_cuda@katamail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
82936f295f
commit
6422f63321
@ -344,7 +344,10 @@ void usage_with_options_internal(const char * const *usagestr,
|
|||||||
break;
|
break;
|
||||||
case OPTION_INTEGER:
|
case OPTION_INTEGER:
|
||||||
if (opts->flags & PARSE_OPT_OPTARG)
|
if (opts->flags & PARSE_OPT_OPTARG)
|
||||||
pos += fprintf(stderr, "[<n>]");
|
if (opts->long_name)
|
||||||
|
pos += fprintf(stderr, "[=<n>]");
|
||||||
|
else
|
||||||
|
pos += fprintf(stderr, "[<n>]");
|
||||||
else
|
else
|
||||||
pos += fprintf(stderr, " <n>");
|
pos += fprintf(stderr, " <n>");
|
||||||
break;
|
break;
|
||||||
@ -355,12 +358,18 @@ void usage_with_options_internal(const char * const *usagestr,
|
|||||||
case OPTION_STRING:
|
case OPTION_STRING:
|
||||||
if (opts->argh) {
|
if (opts->argh) {
|
||||||
if (opts->flags & PARSE_OPT_OPTARG)
|
if (opts->flags & PARSE_OPT_OPTARG)
|
||||||
pos += fprintf(stderr, " [<%s>]", opts->argh);
|
if (opts->long_name)
|
||||||
|
pos += fprintf(stderr, "[=<%s>]", opts->argh);
|
||||||
|
else
|
||||||
|
pos += fprintf(stderr, "[<%s>]", opts->argh);
|
||||||
else
|
else
|
||||||
pos += fprintf(stderr, " <%s>", opts->argh);
|
pos += fprintf(stderr, " <%s>", opts->argh);
|
||||||
} else {
|
} else {
|
||||||
if (opts->flags & PARSE_OPT_OPTARG)
|
if (opts->flags & PARSE_OPT_OPTARG)
|
||||||
pos += fprintf(stderr, " [...]");
|
if (opts->long_name)
|
||||||
|
pos += fprintf(stderr, "[=...]");
|
||||||
|
else
|
||||||
|
pos += fprintf(stderr, "[...]");
|
||||||
else
|
else
|
||||||
pos += fprintf(stderr, " ...");
|
pos += fprintf(stderr, " ...");
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ usage: some-command [options] <args>...
|
|||||||
--bar ... some cool option --bar with an argument
|
--bar ... some cool option --bar with an argument
|
||||||
|
|
||||||
An option group Header
|
An option group Header
|
||||||
-C [...] option C with an optional argument
|
-C[...] option C with an optional argument
|
||||||
|
|
||||||
Extras
|
Extras
|
||||||
--extra1 line above used to cause a segfault but no longer does
|
--extra1 line above used to cause a segfault but no longer does
|
||||||
|
Loading…
Reference in New Issue
Block a user