summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorStephen Boyd <bebarino@gmail.com>2009-06-04 16:43:57 -0700
committerJunio C Hamano <gitster@pobox.com>2009-06-06 13:25:34 -0700
commit34aec9f573af8e6fbe06285d660d9e1a84950e4c (patch)
tree86b8e29169d7b03dcedd30cdd1faaadc4b225125 /parse-options.c
parente3a0ca878457ecc70d0065802fcb0c6875c6b671 (diff)
downloadgit-34aec9f573af8e6fbe06285d660d9e1a84950e4c.tar.gz
parse-options: simplify usage argh handling
Simplify the argh printing by simply calling usage_argh() if the option can take an argument. Update macros defined in parse-options.h to set the PARSE_OPT_NOARG flag. The only other user of custom non-argument taking options is git-apply (in this case OPTION_BOOLEAN for deprecated options). Update it to set the PARSE_OPT_NOARG flag. Thanks to Ren辿 Scharfe for the suggestion and starter patch. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Reviewd-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c33
1 files changed, 4 insertions, 29 deletions
diff --git a/parse-options.c b/parse-options.c
index 48ba62b0d8..e469fc06fa 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -440,7 +440,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>]";
@@ -448,7 +448,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
@@ -500,33 +500,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_CALLBACK:
- if (opts->flags & PARSE_OPT_NOARG)
- break;
- /* FALLTHROUGH */
- case OPTION_INTEGER:
- /* 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;