[PATCH 2/2] allow mangling short options which take integer arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch allows you to do things like for example

  $ git <cmd> -bn100

where -b is a boolean and -n is an integer option.

Signed-off-by: Clemens Buchacher <drizzd@xxxxxx>
---

 parse-options.c |    2 +-
 parse-options.h |    5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index 4f16f37..bfe01ee 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -48,7 +48,7 @@ static int get_value(struct parse_opt_ctx_t *p,
 	const int unset = flags & OPT_UNSET;
 	int err;
 
-	if (many && !(opt->flags & PARSE_OPT_NOARG))
+	if (many && !(opt->flags & (PARSE_OPT_NOARG | PARSE_OPT_MANY)))
 		return opterror(opt, "must not be mangled with other options", flags);
 	if (unset && p->opt)
 		return opterror(opt, "takes no value", flags);
diff --git a/parse-options.h b/parse-options.h
index f295a2c..33ce529 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -37,6 +37,7 @@ enum parse_opt_option_flags {
 	PARSE_OPT_NODASH = 32,
 	PARSE_OPT_LITERAL_ARGHELP = 64,
 	PARSE_OPT_NEGHELP = 128,
+	PARSE_OPT_MANY = 256,
 };
 
 struct option;
@@ -84,6 +85,8 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
  *   PARSE_OPT_NEGHELP: says that the long option should always be shown with
  *				the --no prefix in the usage message. Sometimes
  *				useful for users of OPTION_NEGBIT.
+ *   PARSE_OPT_MANY: the short option may be mangled, despite a possible
+ *				argument.
  *
  * `callback`::
  *   pointer to the callback to use for OPTION_CALLBACK.
@@ -121,7 +124,7 @@ struct option {
 				      (h), PARSE_OPT_NOARG, NULL, (i) }
 #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG, NULL, (p) }
-#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), "n", (h) }
+#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), "n", (h), PARSE_OPT_MANY }
 #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }
 #define OPT_DATE(s, l, v, h) \
 	{ OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \
-- 
1.6.5.rc1.214.g13c5a

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]