summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f858c64)
raw | patch | inline | side by side (parent: f858c64)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Wed, 28 Sep 2011 17:44:30 +0000 (19:44 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 28 Sep 2011 19:46:21 +0000 (12:46 -0700) |
Add OPT_NOOP_NOARG, a helper macro to define deprecated options in a
standard way. The help text is taken from the no-op option -r of
git revert.
The callback could be made to emit a (conditional?) warning later. And
we could also add OPT_NOOP (requiring an argument) etc. as needed.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
standard way. The help text is taken from the no-op option -r of
git revert.
The callback could be made to emit a (conditional?) warning later. And
we could also add OPT_NOOP (requiring an argument) etc. as needed.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index acf17607dfced869ed9709decbe11a1828659cfa..4b92514f60d65232e955cd5dddbeb5318add7274 100644 (file)
"auto", set `int_var` to 1 if stdout is a tty or a pager,
0 otherwise.
+`OPT_NOOP_NOARG(short, long)`::
+ Introduce an option that has no effect and takes no arguments.
+ Use it to hide deprecated options that are still to be recognized
+ and ignored silently.
+
The last element of the array must be `OPT_END()`.
diff --git a/parse-options-cb.c b/parse-options-cb.c
index 6db0921fc1fde3b5fbf829577bdd019ae95462e0..0de5fb168a5c1b86c50be0d0c3f2d7228e7159a1 100644 (file)
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
string_list_append(v, xstrdup(arg));
return 0;
}
+
+int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
+{
+ return 0;
+}
diff --git a/parse-options.h b/parse-options.h
index 22c0273052c93bde773fa573988a4eac0b2ed495..2e811dc7da8e6adc7ebce1a9929e8c345424fe4a 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
{ OPTION_CALLBACK, (s), (l), (v), "when", (h), PARSE_OPT_OPTARG, \
parse_opt_color_flag_cb, (intptr_t)"always" }
+#define OPT_NOOP_NOARG(s, l) \
+ { OPTION_CALLBACK, (s), (l), NULL, NULL, \
+ "no-op (backward compatibility)", \
+ PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
+
/* Deprecated synonym */
#define OPT_BOOLEAN OPT_COUNTUP
extern int parse_opt_with_commit(const struct option *, const char *, int);
extern int parse_opt_tertiary(const struct option *, const char *, int);
extern int parse_opt_string_list(const struct option *, const char *, int);
+extern int parse_opt_noop_cb(const struct option *, const char *, int);
#define OPT__VERBOSE(var, h) OPT_BOOLEAN('v', "verbose", (var), (h))
#define OPT__QUIET(var, h) OPT_BOOLEAN('q', "quiet", (var), (h))
index 007f39d5e1dca6eff7e01969282c4cf2dc1bb57a..a1e4616febe6c67f67ab2b4380610abc92468ba5 100755 (executable)
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
test_expect_success 'long options' '
test-parse-options --boolean --integer 1729 --boolean --string2=321 \
--verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
- > output 2> output.err &&
+ --obsolete > output 2> output.err &&
test ! -s output.err &&
test_cmp expect output
'
diff --git a/test-parse-options.c b/test-parse-options.c
index 91a5701657556e07b4f4daafa947346d3b197cd1..36487c402b264433a3bfda7f84ef9c9a8df8cbb7 100644 (file)
--- a/test-parse-options.c
+++ b/test-parse-options.c
OPT_STRING(0, "string2", &string, "str", "get another string"),
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
OPT_STRING('o', NULL, &string, "str", "get another string"),
+ OPT_NOOP_NOARG(0, "obsolete"),
OPT_SET_PTR(0, "default-string", &string,
"set string to default", (unsigned long)"default"),
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),