From: Michael Haggerty Date: Mon, 05 Sep 2016 09:44:52 GMT Subject: [PATCH v3 7/8] parse-options: add parse_opt_unknown_cb() Message-ID: <963d6e9bce6348af0d5a7ad1284b64e97d28a2a2.1473068229.git.mhagger@alum.mit.edu> In-Reply-To: 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 --- See the next patch for the reason I implemented this change. Let me know if there is an easier way to do this. parse-options-cb.c | 12 ++++++++++++ parse-options.h | 1 + 2 files changed, 13 insertions(+) diff --git a/parse-options-cb.c b/parse-options-cb.c index 9667bc7..b5d9209 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -159,6 +159,18 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset) } /** + * Report that the option is unknown, so that other code can handle + * it. This can be used as a callback together with + * OPTION_LOWLEVEL_CALLBACK to allow an option to be documented in the + * "-h" output even if it's not being handled directly by + * parse_options(). + */ +int parse_opt_unknown_cb(const struct option *opt, const char *arg, int unset) +{ + return -2; +} + +/** * Recreates the command-line option in the strbuf. */ static int recreate_opt(struct strbuf *sb, const struct option *opt, diff --git a/parse-options.h b/parse-options.h index 78f8384..dcd8a09 100644 --- a/parse-options.h +++ b/parse-options.h @@ -228,6 +228,7 @@ extern int parse_opt_commits(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); +extern int parse_opt_unknown_cb(const struct option *, const char *, int); extern int parse_opt_passthru(const struct option *, const char *, int); extern int parse_opt_passthru_argv(const struct option *, const char *, int); -- 2.9.3