summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-06-18 10:36:22 -0700
committerJunio C Hamano <gitster@pobox.com>2009-06-18 10:36:22 -0700
commitd978ead4c3933425f54142f2c3fab7f5071e36ef (patch)
tree18cc9e856c684a6691e465e5e2011530eafa0dfc /parse-options.c
parent3b91202150fef842f210668cd84fd52142dffd5c (diff)
parent34aec9f573af8e6fbe06285d660d9e1a84950e4c (diff)
downloadgit-d978ead4c3933425f54142f2c3fab7f5071e36ef.tar.gz
Merge branch 'sb/parse-options-integer'
* sb/parse-options-integer: parse-options: simplify usage argh handling parse-options: make OPT_INTEGER's argh explicit
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c40
1 files changed, 4 insertions, 36 deletions
diff --git a/parse-options.c b/parse-options.c
index 79de18b37e..34282adde5 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -464,7 +464,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
static int usage_argh(const struct option *opts)
{
const char *s;
- int literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP;
+ int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
if (opts->flags & PARSE_OPT_OPTARG)
if (opts->long_name)
s = literal ? "[=%s]" : "[=<%s>]";
@@ -472,7 +472,7 @@ static int usage_argh(const struct option *opts)
s = literal ? "[%s]" : "[<%s>]";
else
s = literal ? " %s" : " <%s>";
- return fprintf(stderr, s, opts->argh);
+ return fprintf(stderr, s, opts->argh ? opts->argh : "...");
}
#define USAGE_OPTS_WIDTH 24
@@ -524,40 +524,8 @@ int usage_with_options_internal(const char * const *usagestr,
if (opts->type == OPTION_NUMBER)
pos += fprintf(stderr, "-NUM");
- switch (opts->type) {
- case OPTION_ARGUMENT:
- break;
- case OPTION_INTEGER:
- if (opts->flags & PARSE_OPT_OPTARG)
- if (opts->long_name)
- pos += fprintf(stderr, "[=<n>]");
- else
- pos += fprintf(stderr, "[<n>]");
- else
- pos += fprintf(stderr, " <n>");
- break;
- case OPTION_CALLBACK:
- if (opts->flags & PARSE_OPT_NOARG)
- break;
- /* FALLTHROUGH */
- case OPTION_FILENAME:
- /* FALLTHROUGH */
- case OPTION_STRING:
- if (opts->argh)
- pos += usage_argh(opts);
- else {
- if (opts->flags & PARSE_OPT_OPTARG)
- if (opts->long_name)
- pos += fprintf(stderr, "[=...]");
- else
- pos += fprintf(stderr, "[...]");
- else
- pos += fprintf(stderr, " ...");
- }
- break;
- default: /* OPTION_{BIT,BOOLEAN,NUMBER,SET_INT,SET_PTR} */
- break;
- }
+ if (!(opts->flags & PARSE_OPT_NOARG))
+ pos += usage_argh(opts);
if (pos <= USAGE_OPTS_WIDTH)
pad = USAGE_OPTS_WIDTH - pos;