Skip to content

Commit ce564eb

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 433860f commit ce564eb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

parse-options-cb.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
153153
return 0;
154154
}
155155

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+
156168
/**
157169
* Recreates the command-line option in the strbuf.
158170
*/

parse-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ extern int parse_opt_commits(const struct option *, const char *, int);
228228
extern int parse_opt_tertiary(const struct option *, const char *, int);
229229
extern int parse_opt_string_list(const struct option *, const char *, int);
230230
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);
231232
extern int parse_opt_passthru(const struct option *, const char *, int);
232233
extern int parse_opt_passthru_argv(const struct option *, const char *, int);
233234

0 commit comments

Comments
 (0)