diff --git a/cmd/ifquery.c b/cmd/ifquery.c index dc9cfbe..0612823 100644 --- a/cmd/ifquery.c +++ b/cmd/ifquery.c @@ -158,15 +158,6 @@ print_interface_property(struct lif_interface *iface, const char *property) } } -void -ifquery_usage(int status) -{ - fprintf(stderr, "usage: ifquery [options] \n"); - fprintf(stderr, " ifquery [options] --list\n"); - - exit(status); -} - void list_interfaces(struct lif_dict *collection, struct match_options *opts) { @@ -289,7 +280,7 @@ ifquery_main(int argc, char *argv[]) /* --list --state is not allowed */ if (listing && listing_stat) - ifquery_usage(EXIT_FAILURE); + generic_usage(self_applet, EXIT_FAILURE); if (listing) { @@ -303,7 +294,7 @@ ifquery_main(int argc, char *argv[]) } if (optind >= argc) - ifquery_usage(EXIT_FAILURE); + generic_usage(self_applet, EXIT_FAILURE); int idx = optind; for (; idx < argc; idx++) @@ -337,6 +328,6 @@ struct if_applet ifquery_applet = { .name = "ifquery", .desc = "query interface configuration", .main = ifquery_main, - .usage = ifquery_usage, + .usage = "ifquery [options] \n ifquery [options] --list", .groups = { &global_option_group, &match_option_group, &exec_option_group, &local_option_group }, }; diff --git a/cmd/ifupdown.c b/cmd/ifupdown.c index 2c4143a..45410a7 100644 --- a/cmd/ifupdown.c +++ b/cmd/ifupdown.c @@ -320,11 +320,9 @@ ifupdown_main(int argc, char *argv[]) struct if_applet ifup_applet = { .name = "ifup", .main = ifupdown_main, - .usage = ifupdown_usage }; struct if_applet ifdown_applet = { .name = "ifdown", .main = ifupdown_main, - .usage = ifupdown_usage }; diff --git a/cmd/multicall-options.c b/cmd/multicall-options.c index 30e7db4..9037264 100644 --- a/cmd/multicall-options.c +++ b/cmd/multicall-options.c @@ -21,7 +21,7 @@ #include #include "cmd/multicall.h" -static void +void generic_usage(const struct if_applet *applet, int result) { fprintf(stderr, "%s", applet->name); @@ -30,6 +30,9 @@ generic_usage(const struct if_applet *applet, int result) fprintf(stderr, "\n"); + if (applet->usage != NULL) + fprintf(stderr, "\nUsage:\n %s\n", applet->usage); + size_t iter; for (iter = 0; applet->groups[iter] != NULL; iter++) { diff --git a/cmd/multicall.c b/cmd/multicall.c index 9c8a891..ccb7688 100644 --- a/cmd/multicall.c +++ b/cmd/multicall.c @@ -102,6 +102,5 @@ multicall_usage(int status) struct if_applet ifupdown_applet = { .name = "ifupdown", .main = multicall_main, - .usage = multicall_usage, .groups = { &global_option_group, NULL } }; diff --git a/cmd/multicall.h b/cmd/multicall.h index cfbadd5..23cb836 100644 --- a/cmd/multicall.h +++ b/cmd/multicall.h @@ -42,8 +42,8 @@ struct if_option_group { struct if_applet { const char *name; const char *desc; + const char *usage; int (*const main)(int argc, char *argv[]); - void (*const usage)(int status); const struct if_option_group *groups[16]; }; @@ -70,4 +70,6 @@ extern struct if_option_group match_option_group; extern struct lif_execute_opts exec_opts; extern struct if_option_group exec_option_group; +void generic_usage(const struct if_applet *applet, int result); + #endif