Merge branch 'ab/parse-options-cleanup'
Random changes to parse-options implementation.
* ab/parse-options-cleanup:
parse-options: change OPT_{SHORT,UNSET} to an enum
parse-options tests: test optname() output
parse-options.[ch]: make opt{bug,name}() "static"
commit-graph: stop using optname()
parse-options.c: move optname() earlier in the file
parse-options.h: make the "flags" in "struct option" an enum
parse-options.c: use exhaustive "case" arms for "enum parse_opt_result"
parse-options.[ch]: consistently use "enum parse_opt_result"
parse-options.[ch]: consistently use "enum parse_opt_flags"
parse-options.h: move PARSE_OPT_SHELL_EVAL between enums
This commit is contained in:
@@ -33,6 +33,7 @@ enum parse_opt_flags {
|
||||
PARSE_OPT_KEEP_UNKNOWN = 1 << 3,
|
||||
PARSE_OPT_NO_INTERNAL_HELP = 1 << 4,
|
||||
PARSE_OPT_ONE_SHOT = 1 << 5,
|
||||
PARSE_OPT_SHELL_EVAL = 1 << 6,
|
||||
};
|
||||
|
||||
enum parse_opt_option_flags {
|
||||
@@ -44,7 +45,6 @@ enum parse_opt_option_flags {
|
||||
PARSE_OPT_NODASH = 1 << 5,
|
||||
PARSE_OPT_LITERAL_ARGHELP = 1 << 6,
|
||||
PARSE_OPT_FROM_ALIAS = 1 << 7,
|
||||
PARSE_OPT_SHELL_EVAL = 1 << 8,
|
||||
PARSE_OPT_NOCOMPLETE = 1 << 9,
|
||||
PARSE_OPT_COMP_ARG = 1 << 10,
|
||||
PARSE_OPT_CMDMODE = 1 << 11,
|
||||
@@ -134,7 +134,7 @@ struct option {
|
||||
const char *argh;
|
||||
const char *help;
|
||||
|
||||
int flags;
|
||||
enum parse_opt_option_flags flags;
|
||||
parse_opt_cb *callback;
|
||||
intptr_t defval;
|
||||
parse_opt_ll_cb *ll_callback;
|
||||
@@ -213,9 +213,11 @@ struct option {
|
||||
* untouched and parse_options() returns the number of options
|
||||
* processed.
|
||||
*/
|
||||
int parse_options(int argc, const char **argv, const char *prefix,
|
||||
const struct option *options,
|
||||
const char * const usagestr[], int flags);
|
||||
enum parse_opt_result parse_options(int argc, const char **argv,
|
||||
const char *prefix,
|
||||
const struct option *options,
|
||||
const char * const usagestr[],
|
||||
enum parse_opt_flags flags);
|
||||
|
||||
NORETURN void usage_with_options(const char * const *usagestr,
|
||||
const struct option *options);
|
||||
@@ -224,9 +226,6 @@ NORETURN void usage_msg_opt(const char *msg,
|
||||
const char * const *usagestr,
|
||||
const struct option *options);
|
||||
|
||||
int optbug(const struct option *opt, const char *reason);
|
||||
const char *optname(const struct option *opt, int flags);
|
||||
|
||||
/*
|
||||
* Use these assertions for callbacks that expect to be called with NONEG and
|
||||
* NOARG respectively, and do not otherwise handle the "unset" and "arg"
|
||||
@@ -264,7 +263,7 @@ struct parse_opt_ctx_t {
|
||||
const char **out;
|
||||
int argc, cpidx, total;
|
||||
const char *opt;
|
||||
int flags;
|
||||
enum parse_opt_flags flags;
|
||||
const char *prefix;
|
||||
const char **alias_groups; /* must be in groups of 3 elements! */
|
||||
struct option *updated_options;
|
||||
@@ -272,11 +271,12 @@ struct parse_opt_ctx_t {
|
||||
|
||||
void parse_options_start(struct parse_opt_ctx_t *ctx,
|
||||
int argc, const char **argv, const char *prefix,
|
||||
const struct option *options, int flags);
|
||||
const struct option *options,
|
||||
enum parse_opt_flags flags);
|
||||
|
||||
int parse_options_step(struct parse_opt_ctx_t *ctx,
|
||||
const struct option *options,
|
||||
const char * const usagestr[]);
|
||||
enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
|
||||
const struct option *options,
|
||||
const char * const usagestr[]);
|
||||
|
||||
int parse_options_end(struct parse_opt_ctx_t *ctx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user