diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-05-25 00:59:29 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-05-25 00:59:29 -0700 |
commit | b064e2fc3d197c3c691fe89c43d1bf79f64fcdf7 (patch) | |
tree | cbb39054fa81329ff874cb71679221af448583dc /parse-options.c | |
parent | ee969693c5e77e1b5ebda45bead569806d31b379 (diff) | |
parent | 57343652a55bdc3e7f3cf8c6def94dac482c72e5 (diff) | |
download | git-b064e2fc3d197c3c691fe89c43d1bf79f64fcdf7.tar.gz |
Merge branch 'sb/show-branch-parse-options' into sb/opt-filename
* sb/show-branch-parse-options:
show-branch: migrate to parse-options API
parse-options: add PARSE_OPT_LITERAL_ARGHELP for complicated argh's
Conflicts:
parse-options.h
Diffstat (limited to 'parse-options.c')
-rw-r--r-- | parse-options.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/parse-options.c b/parse-options.c index c52b8ccf59..1d25b94c72 100644 --- a/parse-options.c +++ b/parse-options.c @@ -412,6 +412,20 @@ int parse_options(int argc, const char **argv, const struct option *options, return parse_options_end(&ctx); } +static int usage_argh(const struct option *opts) +{ + const char *s; + int literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP; + if (opts->flags & PARSE_OPT_OPTARG) + if (opts->long_name) + s = literal ? "[=%s]" : "[=<%s>]"; + else + s = literal ? "[%s]" : "[<%s>]"; + else + s = literal ? " %s" : " <%s>"; + return fprintf(stderr, s, opts->argh); +} + #define USAGE_OPTS_WIDTH 24 #define USAGE_GAP 2 @@ -478,15 +492,9 @@ int usage_with_options_internal(const char * const *usagestr, break; /* FALLTHROUGH */ case OPTION_STRING: - if (opts->argh) { - if (opts->flags & PARSE_OPT_OPTARG) - 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->argh) + pos += usage_argh(opts); + else { if (opts->flags & PARSE_OPT_OPTARG) if (opts->long_name) pos += fprintf(stderr, "[=...]"); |