parseopt: add OPT_NOOP_NOARG
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>
René Scharfe committed
Sep 28, 2011 at 19:44 UTC
6acec0380bfcd5e3f91c9100bf4d415db8f7acfd
5 files changed
+18
-1
Documentation/technical/api-parse-options.txt
+5
@@ -204,6 +204,11 @@ There are some macros to easily define options:
204
"auto", set `int_var` to 1 if stdout is a tty or a pager,
205
0 otherwise.
206
207
+`OPT_NOOP_NOARG(short, long)`::
208
+ Introduce an option that has no effect and takes no arguments.
209
+ Use it to hide deprecated options that are still to be recognized
210
+ and ignored silently.
211
+
212
213
The last element of the array must be `OPT_END()`.
214
parse-options-cb.c
+5
@@ -123,3 +123,8 @@ int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
123
string_list_append(v, xstrdup(arg));
124
return 0;
125
}
126
+
127
+int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
128
+{
129
+ return 0;
130
+}
parse-options.h
+6
@@ -153,6 +153,11 @@ struct option {
153
{ OPTION_CALLBACK, (s), (l), (v), "when", (h), PARSE_OPT_OPTARG, \
154
parse_opt_color_flag_cb, (intptr_t)"always" }
155
156
+#define OPT_NOOP_NOARG(s, l) \
157
+ { OPTION_CALLBACK, (s), (l), NULL, NULL, \
158
+ "no-op (backward compatibility)", \
159
+ PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
160
+
161
/* Deprecated synonym */
162
#define OPT_BOOLEAN OPT_COUNTUP
163
@@ -216,6 +221,7 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
221
extern int parse_opt_with_commit(const struct option *, const char *, int);
222
extern int parse_opt_tertiary(const struct option *, const char *, int);
223
extern int parse_opt_string_list(const struct option *, const char *, int);
224
+extern int parse_opt_noop_cb(const struct option *, const char *, int);
225
226
#define OPT__VERBOSE(var, h) OPT_BOOLEAN('v', "verbose", (var), (h))
227
#define OPT__QUIET(var, h) OPT_BOOLEAN('q', "quiet", (var), (h))
t/t0040-parse-options.sh
+1
-1
@@ -87,7 +87,7 @@ EOF
87
test_expect_success 'long options' '
88
test-parse-options --boolean --integer 1729 --boolean --string2=321 \
89
--verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
90
- > output 2> output.err &&
90
+ --obsolete > output 2> output.err &&
91
test ! -s output.err &&
92
test_cmp expect output
93
'
test-parse-options.c
+1
@@ -54,6 +54,7 @@ int main(int argc, const char **argv)
54
OPT_STRING(0, "string2", &string, "str", "get another string"),
55
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
56
OPT_STRING('o', NULL, &string, "str", "get another string"),
57
+ OPT_NOOP_NOARG(0, "obsolete"),
58
OPT_SET_PTR(0, "default-string", &string,
59
"set string to default", (unsigned long)"default"),
60
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),