Merge branch 'jc/parseopt-command-modes'
authorJunio C Hamano <gitster@pobox.com>
Wed, 4 Sep 2013 19:37:52 +0000 (12:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Sep 2013 19:37:52 +0000 (12:37 -0700)
Many commands use --dashed-option as a operation mode selector
(e.g. "git tag --delete") that the user can use at most one
(e.g. "git tag --delete --verify" is a nonsense) and you cannot
negate (e.g. "git tag --no-delete" is a nonsense). Make it easier
for users of parse_options() to enforce these restrictions.

* jc/parseopt-command-modes:
tag: use OPT_CMDMODE
parse-options: add OPT_CMDMODE()

1  2 
parse-options.h
diff --combined parse-options.h
index 9b94596e4aa113518d502502a0ca1bf804a60cbc,2404e06732366dd325c2f32c0453c3bdee8590dc..f37fc88143f0cc0277b33d55ec92cc43034774cf
@@@ -13,6 -13,7 +13,7 @@@ enum parse_opt_type 
        OPTION_COUNTUP,
        OPTION_SET_INT,
        OPTION_SET_PTR,
+       OPTION_CMDMODE,
        /* options with arguments (usually) */
        OPTION_STRING,
        OPTION_INTEGER,
@@@ -130,6 -131,8 +131,8 @@@ struct option 
  #define OPT_BOOL(s, l, v, h)        OPT_SET_INT(s, l, v, h, 1)
  #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \
                                      (h), PARSE_OPT_NOARG, NULL, (p) }
+ #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
+                                     (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
  #define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
  #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }
  #define OPT_STRING_LIST(s, l, v, a, h) \
@@@ -180,7 -183,7 +183,7 @@@ extern NORETURN void usage_msg_opt(cons
  
  extern int optbug(const struct option *opt, const char *reason);
  extern int opterror(const struct option *opt, const char *reason, int flags);
 -#if defined(__GNUC__) && ! defined(clang)
 +#if defined(__GNUC__) && ! defined(__clang__)
  #define opterror(o,r,f) (opterror((o),(r),(f)), -1)
  #endif