btrfs-progs: pass cmd_struct to usage()

Now that every call site has a cmd_struct, we can just pass the cmd_struct
to usage to print the usager information.  This allows us to interpret
the format flags we'll add later in this series to inform the user of
which output formats any given command supports.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Jeff Mahoney 2018-03-06 21:54:38 -05:00 committed by David Sterba
parent be0f5c1944
commit 91a1476d53
12 changed files with 29 additions and 37 deletions

View file

@ -9960,7 +9960,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
break;
case '?':
case 'h':
usage(cmd_check_usage);
usage(cmd);
case GETOPT_VAL_REPAIR:
printf("enabling repair mode\n");
repair = 1;
@ -10011,7 +10011,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
}
if (check_argc_exact(argc - optind, 1))
usage(cmd_check_usage);
usage(cmd);
if (ctx.progress_enabled) {
ctx.tp = TASK_NOTHING;

View file

@ -151,7 +151,6 @@ static int _cmd_device_remove(const struct cmd_struct *cmd,
char *mntpnt;
int i, fdmnt, ret = 0;
DIR *dirstream = NULL;
const char * const *usagestr = cmd->usagestr;
clean_args_no_options(cmd, argc, argv);
@ -338,10 +337,10 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
devstart = optind;
if (all && forget)
usage(cmd_device_scan_usage);
usage(cmd);
if (all && check_argc_max(argc - optind, 1))
usage(cmd_device_scan_usage);
usage(cmd);
if (all || argc - optind == 0) {
if (forget) {

View file

@ -724,7 +724,7 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
if (argc > optind) {
search = argv[optind];
if (*search == 0)
usage(cmd_filesystem_show_usage);
usage(cmd);
type = check_arg_type(search);
/*

View file

@ -253,8 +253,7 @@ static int setget_prop(int types, const char *object,
}
static int parse_args(int argc, char **argv,
const char * const *usage_str,
static int parse_args(const struct cmd_struct *cmd, int argc, char **argv,
int *types, char **object,
char **name, char **value, int min_nonopt_args)
{
@ -273,7 +272,7 @@ static int parse_args(int argc, char **argv,
type_str = optarg;
break;
default:
usage_unknown_option(usage_str, argv);
usage_unknown_option(cmd->usagestr, argv);
}
}
@ -348,8 +347,7 @@ static int cmd_property_get(const struct cmd_struct *cmd,
char *name = NULL;
int types = 0;
if (parse_args(argc, argv, cmd_property_get_usage, &types, &object,
&name, NULL, 1))
if (parse_args(cmd, argc, argv, &types, &object, &name, NULL, 1))
return 1;
if (name)
@ -378,8 +376,7 @@ static int cmd_property_set(const struct cmd_struct *cmd,
char *value = NULL;
int types = 0;
if (parse_args(argc, argv, cmd_property_set_usage, &types, &object,
&name, &value, 3))
if (parse_args(cmd, argc, argv, &types, &object, &name, &value, 3))
return 1;
ret = setget_prop(types, object, name, value);
@ -403,8 +400,7 @@ static int cmd_property_list(const struct cmd_struct *cmd,
char *object = NULL;
int types = 0;
if (parse_args(argc, argv, cmd_property_list_usage, &types, &object,
NULL, NULL, 1))
if (parse_args(cmd, argc, argv, &types, &object, NULL, NULL, 1))
return 1;
ret = dump_props(types, object, 1);

View file

@ -487,7 +487,7 @@ static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
args.qgroupid = parse_qgroupid(argv[optind + 1]);
path = argv[optind + 2];
} else
usage(cmd_qgroup_limit_usage);
usage(cmd);
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)

View file

@ -76,7 +76,7 @@ static int cmd_quota_enable(const struct cmd_struct *cmd, int argc, char **argv)
ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
if (ret < 0)
usage(cmd_quota_enable_usage);
usage(cmd);
return ret;
}
static DEFINE_SIMPLE_COMMAND(quota_enable, "enable");
@ -97,7 +97,7 @@ static int cmd_quota_disable(const struct cmd_struct *cmd,
ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv);
if (ret < 0)
usage(cmd_quota_disable_usage);
usage(cmd);
return ret;
}
static DEFINE_SIMPLE_COMMAND(quota_disable, "disable");

View file

@ -1357,9 +1357,9 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
}
if (dump && check_argc_exact(argc - optind, 0))
usage(cmd_receive_usage);
usage(cmd);
if (!dump && check_argc_exact(argc - optind, 1))
usage(cmd_receive_usage);
usage(cmd);
tomnt = argv[optind];

View file

@ -1423,7 +1423,7 @@ static const char * const cmd_restore_usage[] = {
NULL
};
static int cmd_restore(const struct cmd_struct *unused, int argc, char **argv)
static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv)
{
struct btrfs_root *root;
struct btrfs_key key;
@ -1532,9 +1532,9 @@ static int cmd_restore(const struct cmd_struct *unused, int argc, char **argv)
}
if (!list_roots && check_argc_min(argc - optind, 2))
usage(cmd_restore_usage);
usage(cmd);
else if (list_roots && check_argc_min(argc - optind, 1))
usage(cmd_restore_usage);
usage(cmd);
if (fs_location && root_objectid) {
fprintf(stderr, "don't use -f and -r at the same time.\n");

View file

@ -1092,10 +1092,8 @@ static int is_scrub_running_in_kernel(int fd,
return 0;
}
static const char * const cmd_scrub_start_usage[];
static const char * const cmd_scrub_resume_usage[];
static int scrub_start(int argc, char **argv, bool resume)
static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
bool resume)
{
int fdmnt;
int prg_fd = -1;
@ -1173,8 +1171,7 @@ static int scrub_start(int argc, char **argv, bool resume)
force = 1;
break;
default:
usage_unknown_option(resume ? cmd_scrub_resume_usage :
cmd_scrub_start_usage, argv);
usage_unknown_option(cmd->usagestr, argv);
}
}
@ -1585,7 +1582,7 @@ static const char * const cmd_scrub_start_usage[] = {
static int cmd_scrub_start(const struct cmd_struct *cmd, int argc, char **argv)
{
return scrub_start(argc, argv, false);
return scrub_start(cmd, argc, argv, false);
}
static DEFINE_SIMPLE_COMMAND(scrub_start, "start");
@ -1652,7 +1649,7 @@ static const char * const cmd_scrub_resume_usage[] = {
static int cmd_scrub_resume(const struct cmd_struct *cmd, int argc, char **argv)
{
return scrub_start(argc, argv, true);
return scrub_start(cmd, argc, argv, true);
}
static DEFINE_SIMPLE_COMMAND(scrub_resume, "resume");

View file

@ -611,7 +611,7 @@ out:
if (comparer_set)
free(comparer_set);
if (uerr)
usage(cmd_subvol_list_usage);
usage(cmd);
return !!ret;
}
static DEFINE_SIMPLE_COMMAND(subvol_list, "list");
@ -995,7 +995,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv)
if (by_rootid && by_uuid) {
error(
"options --rootid and --uuid cannot be used at the same time");
usage(cmd_subvol_show_usage);
usage(cmd);
}
fullpath = realpath(argv[optind], NULL);

6
help.c
View file

@ -100,7 +100,7 @@ void clean_args_no_options(const struct cmd_struct *cmd, int argc, char *argv[])
switch (c) {
default:
if (cmd->usagestr)
usage(cmd->usagestr);
usage(cmd);
}
}
}
@ -283,9 +283,9 @@ void usage_unknown_option(const char * const *usagestr, char **argv)
}
__attribute__((noreturn))
void usage(const char * const *usagestr)
void usage(const struct cmd_struct *cmd)
{
usage_command_usagestr(usagestr, NULL, true, true);
usage_command_usagestr(cmd->usagestr, NULL, true, true);
exit(1);
}

2
help.h
View file

@ -59,7 +59,7 @@ __attribute__((noreturn))
void usage_unknown_option(const char * const *usagestr, char **argv);
__attribute__((noreturn))
void usage(const char * const *usagestr);
void usage(const struct cmd_struct *cmd);
void usage_command(const struct cmd_struct *cmd, bool full, bool err);
void usage_command_group(const struct cmd_group *grp, bool all, bool err);
void usage_command_group_short(const struct cmd_group *grp);