ifquery: use generic_usage() instead of ifquery_usage()

This commit is contained in:
Ariadne Conill 2020-08-11 23:10:35 -06:00
parent f6d9f65248
commit fda7bfae57
5 changed files with 10 additions and 17 deletions

View file

@ -158,15 +158,6 @@ print_interface_property(struct lif_interface *iface, const char *property)
} }
} }
void
ifquery_usage(int status)
{
fprintf(stderr, "usage: ifquery [options] <interfaces>\n");
fprintf(stderr, " ifquery [options] --list\n");
exit(status);
}
void void
list_interfaces(struct lif_dict *collection, struct match_options *opts) 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 */ /* --list --state is not allowed */
if (listing && listing_stat) if (listing && listing_stat)
ifquery_usage(EXIT_FAILURE); generic_usage(self_applet, EXIT_FAILURE);
if (listing) if (listing)
{ {
@ -303,7 +294,7 @@ ifquery_main(int argc, char *argv[])
} }
if (optind >= argc) if (optind >= argc)
ifquery_usage(EXIT_FAILURE); generic_usage(self_applet, EXIT_FAILURE);
int idx = optind; int idx = optind;
for (; idx < argc; idx++) for (; idx < argc; idx++)
@ -337,6 +328,6 @@ struct if_applet ifquery_applet = {
.name = "ifquery", .name = "ifquery",
.desc = "query interface configuration", .desc = "query interface configuration",
.main = ifquery_main, .main = ifquery_main,
.usage = ifquery_usage, .usage = "ifquery [options] <interfaces>\n ifquery [options] --list",
.groups = { &global_option_group, &match_option_group, &exec_option_group, &local_option_group }, .groups = { &global_option_group, &match_option_group, &exec_option_group, &local_option_group },
}; };

View file

@ -320,11 +320,9 @@ ifupdown_main(int argc, char *argv[])
struct if_applet ifup_applet = { struct if_applet ifup_applet = {
.name = "ifup", .name = "ifup",
.main = ifupdown_main, .main = ifupdown_main,
.usage = ifupdown_usage
}; };
struct if_applet ifdown_applet = { struct if_applet ifdown_applet = {
.name = "ifdown", .name = "ifdown",
.main = ifupdown_main, .main = ifupdown_main,
.usage = ifupdown_usage
}; };

View file

@ -21,7 +21,7 @@
#include <getopt.h> #include <getopt.h>
#include "cmd/multicall.h" #include "cmd/multicall.h"
static void void
generic_usage(const struct if_applet *applet, int result) generic_usage(const struct if_applet *applet, int result)
{ {
fprintf(stderr, "%s", applet->name); fprintf(stderr, "%s", applet->name);
@ -30,6 +30,9 @@ generic_usage(const struct if_applet *applet, int result)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (applet->usage != NULL)
fprintf(stderr, "\nUsage:\n %s\n", applet->usage);
size_t iter; size_t iter;
for (iter = 0; applet->groups[iter] != NULL; iter++) for (iter = 0; applet->groups[iter] != NULL; iter++)
{ {

View file

@ -102,6 +102,5 @@ multicall_usage(int status)
struct if_applet ifupdown_applet = { struct if_applet ifupdown_applet = {
.name = "ifupdown", .name = "ifupdown",
.main = multicall_main, .main = multicall_main,
.usage = multicall_usage,
.groups = { &global_option_group, NULL } .groups = { &global_option_group, NULL }
}; };

View file

@ -42,8 +42,8 @@ struct if_option_group {
struct if_applet { struct if_applet {
const char *name; const char *name;
const char *desc; const char *desc;
const char *usage;
int (*const main)(int argc, char *argv[]); int (*const main)(int argc, char *argv[]);
void (*const usage)(int status);
const struct if_option_group *groups[16]; 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 lif_execute_opts exec_opts;
extern struct if_option_group exec_option_group; extern struct if_option_group exec_option_group;
void generic_usage(const struct if_applet *applet, int result);
#endif #endif