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
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] <interfaces>\n ifquery [options] --list",
.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 = {
.name = "ifup",
.main = ifupdown_main,
.usage = ifupdown_usage
};
struct if_applet ifdown_applet = {
.name = "ifdown",
.main = ifupdown_main,
.usage = ifupdown_usage
};

View file

@ -21,7 +21,7 @@
#include <getopt.h>
#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++)
{

View file

@ -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 }
};

View file

@ -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