diff options
author | Pierre Habouzit <madcoder@debian.org> | 2007-10-16 00:32:38 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-10-29 21:03:31 -0700 |
commit | f481e22a145ed17e85b68bf8ce2de4b80dfa4323 (patch) | |
tree | ac9ae1c08508c0802794bfdb511c6a3d85a46706 /parse-options.c | |
parent | 7f275b91520d31bfbe43ec5a9bbaf8ac6e663ce0 (diff) | |
download | git-f481e22a145ed17e85b68bf8ce2de4b80dfa4323.tar.gz git-f481e22a145ed17e85b68bf8ce2de4b80dfa4323.tar.xz |
parse-options: allow callbacks to take no arguments at all.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'parse-options.c')
-rw-r--r-- | parse-options.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/parse-options.c b/parse-options.c index b4a3b63e9..cc09c98ec 100644 --- a/parse-options.c +++ b/parse-options.c @@ -72,6 +72,11 @@ static int get_value(struct optparse_t *p, case OPTION_CALLBACK: if (flags & OPT_UNSET) return (*opt->callback)(opt, NULL, 1); + if (opt->flags & PARSE_OPT_NOARG) { + if (p->opt && !(flags & OPT_SHORT)) + return opterror(opt, "takes no value", flags); + return (*opt->callback)(opt, NULL, 0); + } if (opt->flags & PARSE_OPT_OPTARG && (!arg || *arg == '-')) return (*opt->callback)(opt, NULL, 0); if (!arg) @@ -261,8 +266,11 @@ void usage_with_options(const char * const *usagestr, else pos += fprintf(stderr, " <n>"); break; - case OPTION_STRING: case OPTION_CALLBACK: + if (opts->flags & PARSE_OPT_NOARG) + break; + /* FALLTHROUGH */ + case OPTION_STRING: if (opts->argh) { if (opts->flags & PARSE_OPT_OPTARG) pos += fprintf(stderr, " [<%s>]", opts->argh); |