mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
Merge branch 'sg/parse-options-h-initializers'
Code clean-up to use designated initializers in parse-options API. * sg/parse-options-h-initializers: parse-options.h: use designated initializers in OPT_* macros parse-options.h: rename _OPT_CONTAINS_OR_WITH()'s parameters parse-options.h: use consistent name for the callback parameters
This commit is contained in:
commit
5f6f7a48da
311
parse-options.h
311
parse-options.h
|
@ -158,71 +158,202 @@ struct option {
|
|||
parse_opt_subcommand_fn *subcommand_fn;
|
||||
};
|
||||
|
||||
#define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \
|
||||
PARSE_OPT_NOARG|(f), NULL, (b) }
|
||||
#define OPT_COUNTUP_F(s, l, v, h, f) { OPTION_COUNTUP, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG|(f) }
|
||||
#define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG | (f), NULL, (i) }
|
||||
#define OPT_BIT_F(s, l, v, h, b, f) { \
|
||||
.type = OPTION_BIT, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG|(f), \
|
||||
.callback = NULL, \
|
||||
.defval = (b), \
|
||||
}
|
||||
#define OPT_COUNTUP_F(s, l, v, h, f) { \
|
||||
.type = OPTION_COUNTUP, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG|(f), \
|
||||
}
|
||||
#define OPT_SET_INT_F(s, l, v, h, i, f) { \
|
||||
.type = OPTION_SET_INT, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG | (f), \
|
||||
.defval = (i), \
|
||||
}
|
||||
#define OPT_BOOL_F(s, l, v, h, f) OPT_SET_INT_F(s, l, v, h, 1, f)
|
||||
#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
|
||||
#define OPT_STRING_F(s, l, v, a, h, f) { OPTION_STRING, (s), (l), (v), (a), (h), (f) }
|
||||
#define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) }
|
||||
#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = (a), \
|
||||
.help = (h), \
|
||||
.flags = (f), \
|
||||
.callback = (cb), \
|
||||
}
|
||||
#define OPT_STRING_F(s, l, v, a, h, f) { \
|
||||
.type = OPTION_STRING, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = (a), \
|
||||
.help = (h), \
|
||||
.flags = (f), \
|
||||
}
|
||||
#define OPT_INTEGER_F(s, l, v, h, f) { \
|
||||
.type = OPTION_INTEGER, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("n"), \
|
||||
.help = (h), \
|
||||
.flags = (f), \
|
||||
}
|
||||
|
||||
#define OPT_END() { OPTION_END }
|
||||
#define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
|
||||
#define OPT_END() { \
|
||||
.type = OPTION_END, \
|
||||
}
|
||||
#define OPT_GROUP(h) { \
|
||||
.type = OPTION_GROUP, \
|
||||
.help = (h), \
|
||||
}
|
||||
#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
|
||||
#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
|
||||
PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \
|
||||
(set), NULL, (clear) }
|
||||
#define OPT_NEGBIT(s, l, v, h, b) { OPTION_NEGBIT, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG, NULL, (b) }
|
||||
#define OPT_BITOP(s, l, v, h, set, clear) { \
|
||||
.type = OPTION_BITOP, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG|PARSE_OPT_NONEG, \
|
||||
.defval = (set), \
|
||||
.extra = (clear), \
|
||||
}
|
||||
#define OPT_NEGBIT(s, l, v, h, b) { \
|
||||
.type = OPTION_NEGBIT, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG, \
|
||||
.defval = (b), \
|
||||
}
|
||||
#define OPT_COUNTUP(s, l, v, h) OPT_COUNTUP_F(s, l, v, h, 0)
|
||||
#define OPT_SET_INT(s, l, v, h, i) OPT_SET_INT_F(s, l, v, h, i, 0)
|
||||
#define OPT_BOOL(s, l, v, h) OPT_BOOL_F(s, l, v, h, 0)
|
||||
#define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
|
||||
#define OPT_CMDMODE_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_CMDMODE|PARSE_OPT_NOARG|PARSE_OPT_NONEG | (f), NULL, (i) }
|
||||
#define OPT_HIDDEN_BOOL(s, l, v, h) { \
|
||||
.type = OPTION_SET_INT, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, \
|
||||
.defval = 1, \
|
||||
}
|
||||
#define OPT_CMDMODE_F(s, l, v, h, i, f) { \
|
||||
.type = OPTION_SET_INT, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_CMDMODE|PARSE_OPT_NOARG|PARSE_OPT_NONEG | (f), \
|
||||
.defval = (i), \
|
||||
}
|
||||
#define OPT_CMDMODE(s, l, v, h, i) OPT_CMDMODE_F(s, l, v, h, i, 0)
|
||||
|
||||
#define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0)
|
||||
#define OPT_MAGNITUDE(s, l, v, h) { OPTION_MAGNITUDE, (s), (l), (v), \
|
||||
N_("n"), (h), PARSE_OPT_NONEG }
|
||||
#define OPT_MAGNITUDE(s, l, v, h) { \
|
||||
.type = OPTION_MAGNITUDE, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("n"), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NONEG, \
|
||||
}
|
||||
#define OPT_STRING(s, l, v, a, h) OPT_STRING_F(s, l, v, a, h, 0)
|
||||
#define OPT_STRING_LIST(s, l, v, a, h) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), (a), \
|
||||
(h), 0, &parse_opt_string_list }
|
||||
#define OPT_UYN(s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG, &parse_opt_tertiary }
|
||||
#define OPT_EXPIRY_DATE(s, l, v, h) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0, \
|
||||
parse_opt_expiry_date_cb }
|
||||
#define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f)
|
||||
#define OPT_NUMBER_CALLBACK(v, h, f) \
|
||||
{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \
|
||||
PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) }
|
||||
#define OPT_FILENAME(s, l, v, h) { OPTION_FILENAME, (s), (l), (v), \
|
||||
N_("file"), (h) }
|
||||
#define OPT_COLOR_FLAG(s, l, v, h) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), N_("when"), (h), PARSE_OPT_OPTARG, \
|
||||
parse_opt_color_flag_cb, (intptr_t)"always" }
|
||||
#define OPT_STRING_LIST(s, l, v, a, h) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = (a), \
|
||||
.help = (h), \
|
||||
.callback = &parse_opt_string_list, \
|
||||
}
|
||||
#define OPT_UYN(s, l, v, h) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG, \
|
||||
.callback = &parse_opt_tertiary, \
|
||||
}
|
||||
#define OPT_EXPIRY_DATE(s, l, v, h) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("expiry-date"), \
|
||||
.help = (h), \
|
||||
.callback = parse_opt_expiry_date_cb, \
|
||||
}
|
||||
#define OPT_CALLBACK(s, l, v, a, h, cb) OPT_CALLBACK_F(s, l, v, a, h, 0, cb)
|
||||
#define OPT_NUMBER_CALLBACK(v, h, cb) { \
|
||||
.type = OPTION_NUMBER, \
|
||||
.value = (v), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG, \
|
||||
.callback = (cb), \
|
||||
}
|
||||
#define OPT_FILENAME(s, l, v, h) { \
|
||||
.type = OPTION_FILENAME, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("file"), \
|
||||
.help = (h), \
|
||||
}
|
||||
#define OPT_COLOR_FLAG(s, l, v, h) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("when"), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_OPTARG, \
|
||||
.callback = parse_opt_color_flag_cb, \
|
||||
.defval = (intptr_t)"always", \
|
||||
}
|
||||
|
||||
#define OPT_NOOP_NOARG(s, l) \
|
||||
{ OPTION_CALLBACK, (s), (l), NULL, NULL, \
|
||||
N_("no-op (backward compatibility)"), \
|
||||
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
|
||||
#define OPT_NOOP_NOARG(s, l) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.help = N_("no-op (backward compatibility)"), \
|
||||
.flags = PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, \
|
||||
.callback = parse_opt_noop_cb, \
|
||||
}
|
||||
|
||||
#define OPT_ALIAS(s, l, source_long_name) \
|
||||
{ OPTION_ALIAS, (s), (l), (source_long_name) }
|
||||
#define OPT_ALIAS(s, l, source_long_name) { \
|
||||
.type = OPTION_ALIAS, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (source_long_name), \
|
||||
}
|
||||
|
||||
#define OPT_SUBCOMMAND_F(l, v, fn, f) { \
|
||||
.type = OPTION_SUBCOMMAND, \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.flags = (f), \
|
||||
.subcommand_fn = (fn) }
|
||||
.subcommand_fn = (fn), \
|
||||
}
|
||||
#define OPT_SUBCOMMAND(l, v, fn) OPT_SUBCOMMAND_F((l), (v), (fn), 0)
|
||||
|
||||
/*
|
||||
|
@ -358,34 +489,80 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);
|
|||
|
||||
#define OPT__VERBOSE(var, h) OPT_COUNTUP('v', "verbose", (var), (h))
|
||||
#define OPT__QUIET(var, h) OPT_COUNTUP('q', "quiet", (var), (h))
|
||||
#define OPT__VERBOSITY(var) \
|
||||
{ OPTION_CALLBACK, 'v', "verbose", (var), NULL, N_("be more verbose"), \
|
||||
PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \
|
||||
{ OPTION_CALLBACK, 'q', "quiet", (var), NULL, N_("be more quiet"), \
|
||||
PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
|
||||
#define OPT__VERBOSITY(var) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = 'v', \
|
||||
.long_name = "verbose", \
|
||||
.value = (var), \
|
||||
.help = N_("be more verbose"), \
|
||||
.flags = PARSE_OPT_NOARG, \
|
||||
.callback = &parse_opt_verbosity_cb, \
|
||||
}, { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = 'q', \
|
||||
.long_name = "quiet", \
|
||||
.value = (var), \
|
||||
.help = N_("be more quiet"), \
|
||||
.flags = PARSE_OPT_NOARG, \
|
||||
.callback = &parse_opt_verbosity_cb, \
|
||||
}
|
||||
#define OPT__DRY_RUN(var, h) OPT_BOOL('n', "dry-run", (var), (h))
|
||||
#define OPT__FORCE(var, h, f) OPT_COUNTUP_F('f', "force", (var), (h), (f))
|
||||
#define OPT__ABBREV(var) \
|
||||
{ OPTION_CALLBACK, 0, "abbrev", (var), N_("n"), \
|
||||
N_("use <n> digits to display object names"), \
|
||||
PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }
|
||||
#define OPT__ABBREV(var) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.long_name = "abbrev", \
|
||||
.value = (var), \
|
||||
.argh = N_("n"), \
|
||||
.help = N_("use <n> digits to display object names"), \
|
||||
.flags = PARSE_OPT_OPTARG, \
|
||||
.callback = &parse_opt_abbrev_cb, \
|
||||
}
|
||||
#define OPT__SUPER_PREFIX(var) \
|
||||
OPT_STRING_F(0, "super-prefix", (var), N_("prefix"), \
|
||||
N_("prefixed path to initial superproject"), PARSE_OPT_HIDDEN)
|
||||
|
||||
#define OPT__COLOR(var, h) \
|
||||
OPT_COLOR_FLAG(0, "color", (var), (h))
|
||||
#define OPT_COLUMN(s, l, v, h) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), N_("style"), (h), PARSE_OPT_OPTARG, parseopt_column_callback }
|
||||
#define OPT_PASSTHRU(s, l, v, a, h, f) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), parse_opt_passthru }
|
||||
#define OPT_PASSTHRU_ARGV(s, l, v, a, h, f) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), parse_opt_passthru_argv }
|
||||
#define _OPT_CONTAINS_OR_WITH(name, variable, help, flag) \
|
||||
{ OPTION_CALLBACK, 0, name, (variable), N_("commit"), (help), \
|
||||
PARSE_OPT_LASTARG_DEFAULT | flag, \
|
||||
parse_opt_commits, (intptr_t) "HEAD" \
|
||||
}
|
||||
#define OPT_COLUMN(s, l, v, h) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("style"), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_OPTARG, \
|
||||
.callback = parseopt_column_callback, \
|
||||
}
|
||||
#define OPT_PASSTHRU(s, l, v, a, h, f) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = (a), \
|
||||
.help = (h), \
|
||||
.flags = (f), \
|
||||
.callback = parse_opt_passthru, \
|
||||
}
|
||||
#define OPT_PASSTHRU_ARGV(s, l, v, a, h, f) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.short_name = (s), \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = (a), \
|
||||
.help = (h), \
|
||||
.flags = (f), \
|
||||
.callback = parse_opt_passthru_argv, \
|
||||
}
|
||||
#define _OPT_CONTAINS_OR_WITH(l, v, h, f) { \
|
||||
.type = OPTION_CALLBACK, \
|
||||
.long_name = (l), \
|
||||
.value = (v), \
|
||||
.argh = N_("commit"), \
|
||||
.help = (h), \
|
||||
.flags = PARSE_OPT_LASTARG_DEFAULT | (f), \
|
||||
.callback = parse_opt_commits, \
|
||||
.defval = (intptr_t) "HEAD", \
|
||||
}
|
||||
#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, PARSE_OPT_NONEG)
|
||||
#define OPT_NO_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("no-contains", v, h, PARSE_OPT_NONEG)
|
||||
#define OPT_WITH(v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)
|
||||
|
|
Loading…
Reference in a new issue