diff options
author | Michele Ballabio <barra_cuda@katamail.com> | 2008-06-22 16:39:04 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-06-22 18:14:37 -0700 |
commit | 6422f633216475939f9a6f317e41a164737cbb02 (patch) | |
tree | fdea6594e42337e468184d9caa900e76b0f114b0 | |
parent | 82936f295f803a8f1fbe2d89856e9371baa3536c (diff) | |
download | git-6422f633216475939f9a6f317e41a164737cbb02.tar.gz |
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>
-rw-r--r-- | parse-options.c | 15 | ||||
-rwxr-xr-x | t/t1502-rev-parse-parseopt.sh | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/parse-options.c b/parse-options.c index acf3fe3a1a..f8d52e21fe 100644 --- a/parse-options.c +++ b/parse-options.c @@ -344,7 +344,10 @@ void usage_with_options_internal(const char * const *usagestr, break; case OPTION_INTEGER: if (opts->flags & PARSE_OPT_OPTARG) - pos += fprintf(stderr, "[<n>]"); + if (opts->long_name) + pos += fprintf(stderr, "[=<n>]"); + else + pos += fprintf(stderr, "[<n>]"); else pos += fprintf(stderr, " <n>"); break; @@ -355,12 +358,18 @@ void usage_with_options_internal(const char * const *usagestr, case OPTION_STRING: if (opts->argh) { 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 pos += fprintf(stderr, " <%s>", opts->argh); } else { if (opts->flags & PARSE_OPT_OPTARG) - pos += fprintf(stderr, " [...]"); + if (opts->long_name) + pos += fprintf(stderr, "[=...]"); + else + pos += fprintf(stderr, "[...]"); else pos += fprintf(stderr, " ..."); } diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index d24a47d114..3508d0a612 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -13,7 +13,7 @@ usage: some-command [options] <args>... --bar ... some cool option --bar with an argument An option group Header - -C [...] option C with an optional argument + -C[...] option C with an optional argument Extras --extra1 line above used to cause a segfault but no longer does |