parse-options: add parse_opt_unknown_cb()
Add a new callback function, parse_opt_unknown_cb(), which returns -2 to indicate that the corresponding option is unknown. This can be used to add "-h" documentation for an option that will be handled externally to parse_options(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 5, 2016 at 11:44 UTC
ce564eb1bd541a87152e3546fb7d7a2b460df7ed
2 files changed
+13
parse-options-cb.c
+12
@@ -153,6 +153,18 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
153
return 0;
154
}
155
156
+/**
157
+ * Report that the option is unknown, so that other code can handle
158
+ * it. This can be used as a callback together with
159
+ * OPTION_LOWLEVEL_CALLBACK to allow an option to be documented in the
160
+ * "-h" output even if it's not being handled directly by
161
+ * parse_options().
162
+ */
163
+int parse_opt_unknown_cb(const struct option *opt, const char *arg, int unset)
164
+{
165
+ return -2;
166
+}
167
+
168
/**
169
* Recreates the command-line option in the strbuf.
170
*/
parse-options.h
+1
@@ -228,6 +228,7 @@ extern int parse_opt_commits(const struct option *, const char *, int);
228
extern int parse_opt_tertiary(const struct option *, const char *, int);
229
extern int parse_opt_string_list(const struct option *, const char *, int);
230
extern int parse_opt_noop_cb(const struct option *, const char *, int);
231
+extern int parse_opt_unknown_cb(const struct option *, const char *, int);
232
extern int parse_opt_passthru(const struct option *, const char *, int);
233
extern int parse_opt_passthru_argv(const struct option *, const char *, int);
234