@matheusbsbs / matheus-bagliano / commits / 6422f63321
Fork 0

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>

Michele Ballabio committed Jun 22, 2008 at 16:39 UTC 6422f633216475939f9a6f317e41a164737cbb02
2 files changed +13 -4
parse-options.c
+12 -3
@@ -344,7 +344,10 @@ void usage_with_options_internal(const char * const *usagestr,
344 break;
345 case OPTION_INTEGER:
346 if (opts->flags & PARSE_OPT_OPTARG)
347 - pos += fprintf(stderr, "[<n>]");
347 + if (opts->long_name)
348 + pos += fprintf(stderr, "[=<n>]");
349 + else
350 + pos += fprintf(stderr, "[<n>]");
351 else
352 pos += fprintf(stderr, " <n>");
353 break;
@@ -355,12 +358,18 @@ void usage_with_options_internal(const char * const *usagestr,
358 case OPTION_STRING:
359 if (opts->argh) {
360 if (opts->flags & PARSE_OPT_OPTARG)
358 - pos += fprintf(stderr, " [<%s>]", opts->argh);
361 + if (opts->long_name)
362 + pos += fprintf(stderr, "[=<%s>]", opts->argh);
363 + else
364 + pos += fprintf(stderr, "[<%s>]", opts->argh);
365 else
366 pos += fprintf(stderr, " <%s>", opts->argh);
367 } else {
368 if (opts->flags & PARSE_OPT_OPTARG)
363 - pos += fprintf(stderr, " [...]");
369 + if (opts->long_name)
370 + pos += fprintf(stderr, "[=...]");
371 + else
372 + pos += fprintf(stderr, "[...]");
373 else
374 pos += fprintf(stderr, " ...");
375 }
t/t1502-rev-parse-parseopt.sh
+1 -1
@@ -13,7 +13,7 @@ usage: some-command [options] <args>...
13 --bar ... some cool option --bar with an argument
14
15 An option group Header
16 - -C [...] option C with an optional argument
16 + -C[...] option C with an optional argument
17
18 Extras
19 --extra1 line above used to cause a segfault but no longer does