summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7f275b9)
raw | patch | inline | side by side (parent: 7f275b9)
author | Pierre Habouzit <madcoder@debian.org> | |
Mon, 15 Oct 2007 22:32:38 +0000 (00:32 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 30 Oct 2007 04:03:31 +0000 (21:03 -0700) |
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
parse-options.c | patch | blob | history | |
parse-options.h | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index b4a3b63e9f33b9f2af40fd8cf17dd2aeff312a35..cc09c98ec3fe19d6f9f5f7a58a3c5956bd7c0578 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
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)
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);
diff --git a/parse-options.h b/parse-options.h
index 2558e00a7c0eb12a028f4d2e88f2a8f255716604..3a470e5eb8b1fe5597403487d85484fb0e52e5b9 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
enum parse_opt_option_flags {
PARSE_OPT_OPTARG = 1,
+ PARSE_OPT_NOARG = 2,
};
struct option;