diff --git a/Makefile b/Makefile index f2ad017..a0615be 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/ifquery.c b/cmd/ifquery.c index f84fb28..b1df261 100644 --- a/cmd/ifquery.c +++ b/cmd/ifquery.c @@ -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 }, }; diff --git a/cmd/ifupdown.c b/cmd/ifupdown.c index 1c42a3f..75d9c61 100644 --- a/cmd/ifupdown.c +++ b/cmd/ifupdown.c @@ -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 (;;) { diff --git a/cmd/multicall-options.c b/cmd/multicall-options.c index 415d24a..30e7db4 100644 --- a/cmd/multicall-options.c +++ b/cmd/multicall-options.c @@ -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 = { diff --git a/cmd/multicall.h b/cmd/multicall.h index 97056a2..aa5752e 100644 --- a/cmd/multicall.h +++ b/cmd/multicall.h @@ -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