multicall: migrate match options to shared collection

This commit is contained in:
Ariadne Conill 2020-08-11 22:37:36 -06:00
parent f871002ecc
commit 52509c508c
5 changed files with 17 additions and 33 deletions

View file

@ -41,7 +41,8 @@ LIBIFUPDOWN_LIB = libifupdown.a
MULTICALL_SRC = \
cmd/multicall.c \
cmd/multicall-options.c
cmd/multicall-options.c \
cmd/multicall-match-options.c
MULTICALL_OBJ = ${MULTICALL_SRC:.c=.o}
MULTICALL = ifupdown

View file

@ -174,9 +174,6 @@ ifquery_usage(int status)
fprintf(stderr, " -V, --version show this program's version\n");
fprintf(stderr, " -i, --interfaces FILE use FILE for interface definitions\n");
fprintf(stderr, " -L, --list list matching interfaces\n");
fprintf(stderr, " -a, --auto only match against interfaces hinted as 'auto'\n");
fprintf(stderr, " -I, --include PATTERN only match against interfaces matching PATTERN\n");
fprintf(stderr, " -X, --exclude PATTERN never match against interfaces matching PATTERN\n");
fprintf(stderr, " -P, --pretty-print pretty print the interfaces instead of just listing\n");
fprintf(stderr, " -S, --state-file FILE use FILE for state\n");
fprintf(stderr, " -s, --state show configured state\n");
@ -253,13 +250,8 @@ ifquery_main(int argc, char *argv[])
struct lif_dict state = {};
struct lif_dict collection = {};
struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"interfaces", required_argument, 0, 'i'},
{"list", no_argument, 0, 'L'},
{"auto", no_argument, 0, 'a'},
{"include", required_argument, 0, 'I'},
{"exclude", required_argument, 0, 'X'},
{"pretty-print", no_argument, 0, 'P'},
{"state-file", required_argument, 0, 'S'},
{"state", no_argument, 0, 's'},
@ -268,7 +260,6 @@ ifquery_main(int argc, char *argv[])
{"executor-path", required_argument, 0, 'E'},
{NULL, 0, 0, 0}
};
struct match_options match_opts = {};
bool listing = false, listing_stat = false;
char *state_file = STATE_FILE;
@ -279,27 +270,12 @@ ifquery_main(int argc, char *argv[])
break;
switch (c) {
case 'h':
ifquery_usage(EXIT_SUCCESS);
break;
case 'V':
lif_common_version();
break;
case 'i':
exec_opts.interfaces_file = optarg;
break;
case 'L':
listing = true;
break;
case 'a':
match_opts.is_auto = true;
break;
case 'I':
match_opts.include_pattern = optarg;
break;
case 'X':
match_opts.exclude_pattern = optarg;
break;
case 'P':
match_opts.pretty_print = true;
break;
@ -381,6 +357,8 @@ ifquery_main(int argc, char *argv[])
struct if_applet ifquery_applet = {
.name = "ifquery",
.desc = "query interface configuration",
.main = ifquery_main,
.usage = ifquery_usage
.usage = ifquery_usage,
.groups = { &global_option_group, &match_option_group, NULL },
};

View file

@ -204,7 +204,6 @@ ifupdown_main(int argc, char *argv[])
{"no-lock", no_argument, 0, 'L'},
{NULL, 0, 0, 0}
};
struct match_options match_opts = {};
for (;;)
{

View file

@ -51,7 +51,7 @@ generic_usage(const struct if_applet *applet, int result)
if (opt->long_opt)
fprintf(stderr, "%c --%-30s", opt->short_opt ? ',' : ' ',
opt->long_opt);
opt->long_opt_desc ? opt->long_opt_desc : opt->long_opt);
else
fprintf(stderr, "%34s", "");
@ -73,8 +73,8 @@ generic_usage_request(int short_opt, const struct if_option *option, const char
}
static struct if_option global_options[] = {
{'h', "help", "displays program help", false, generic_usage_request},
{'V', "version", "displays program version", false, (void *) lif_common_version},
{'h', "help", NULL, "this help", false, generic_usage_request},
{'V', "version", NULL, "show this program's version", false, (void *) lif_common_version},
};
struct if_option_group global_option_group = {

View file

@ -27,6 +27,7 @@ struct if_applet;
struct if_option {
char short_opt;
const char *long_opt;
const char *long_opt_desc;
const char *desc;
bool require_argument;
void (*const handle)(int short_opt, const struct if_option *opt, const char *opt_arg, const struct if_applet *applet);
@ -47,18 +48,23 @@ struct if_applet {
};
extern char *argv0;
extern const struct if_applet *self_applet;
extern struct if_option_group global_option_group;
struct match_options {
bool is_auto;
char *exclude_pattern;
char *include_pattern;
const char *exclude_pattern;
const char *include_pattern;
bool pretty_print;
bool dot;
char *property;
const char *property;
};
extern struct match_options match_opts;
extern void process_options(const struct if_applet *applet, int argc, char *argv[]);
extern const struct if_option *lookup_option(const struct if_applet *applet, int opt);
extern struct if_option_group match_option_group;
#endif