btrfs-progs: pass cmd_struct to clean_args_no_options{,_relaxed}
Now that we have a cmd_struct everywhere, we can pass it to clean_args_no_options and have it resolve the usage string from it there. This is necessary for it to pass the cmd_struct to usage() in the next patch. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b44445131f
commit
be0f5c1944
|
@ -691,7 +691,7 @@ static int cmd_balance_pause(const struct cmd_struct *cmd,
|
|||
int ret;
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_balance_pause_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -731,7 +731,7 @@ static int cmd_balance_cancel(const struct cmd_struct *cmd,
|
|||
int ret;
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_balance_cancel_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -772,7 +772,7 @@ static int cmd_balance_resume(const struct cmd_struct *cmd,
|
|||
int fd;
|
||||
int ret;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_balance_resume_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
|
|
@ -151,8 +151,9 @@ 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(argc, argv, cmd->usagestr);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_min(argc - optind, 2))
|
||||
return 1;
|
||||
|
@ -410,7 +411,7 @@ static int cmd_device_ready(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
int ret;
|
||||
char *path;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd->usagestr);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -636,7 +637,7 @@ static int cmd_device_usage(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
|
||||
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
|
||||
|
||||
clean_args_no_options(argc, argv, cmd->usagestr);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_min(argc - optind, 1))
|
||||
return 1;
|
||||
|
|
|
@ -132,7 +132,7 @@ static int cmd_filesystem_df(const struct cmd_struct *cmd,
|
|||
|
||||
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_filesystem_df_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -840,7 +840,7 @@ static int cmd_filesystem_sync(const struct cmd_struct *cmd,
|
|||
{
|
||||
enum btrfs_util_error err;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_filesystem_sync_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -1121,7 +1121,7 @@ static int cmd_filesystem_resize(const struct cmd_struct *cmd,
|
|||
DIR *dirstream = NULL;
|
||||
struct stat st;
|
||||
|
||||
clean_args_no_options_relaxed(argc, argv);
|
||||
clean_args_no_options_relaxed(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 2))
|
||||
return 1;
|
||||
|
@ -1194,7 +1194,7 @@ static const char * const cmd_filesystem_label_usage[] = {
|
|||
static int cmd_filesystem_label(const struct cmd_struct *cmd,
|
||||
int argc, char **argv)
|
||||
{
|
||||
clean_args_no_options(argc, argv, cmd_filesystem_label_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_min(argc - optind, 1) ||
|
||||
check_argc_max(argc - optind, 2))
|
||||
|
|
|
@ -283,7 +283,7 @@ static int cmd_inspect_subvolid_resolve(const struct cmd_struct *cmd,
|
|||
char path[PATH_MAX];
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_inspect_subvolid_resolve_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 2))
|
||||
return 1;
|
||||
|
@ -326,7 +326,7 @@ static int cmd_inspect_rootid(const struct cmd_struct *cmd,
|
|||
u64 rootid;
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_inspect_rootid_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
|
|
@ -35,8 +35,8 @@ static const char * const qgroup_cmd_group_usage[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
static int _cmd_qgroup_assign(int assign, int argc, char **argv,
|
||||
const char * const *usage_str)
|
||||
static int _cmd_qgroup_assign(const struct cmd_struct *cmd, int assign,
|
||||
int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
int fd;
|
||||
|
@ -68,11 +68,11 @@ static int _cmd_qgroup_assign(int assign, int argc, char **argv,
|
|||
rescan = false;
|
||||
break;
|
||||
default:
|
||||
usage_unknown_option(usage_str, argv);
|
||||
usage_unknown_option(cmd->usagestr, argv);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
clean_args_no_options(argc, argv, usage_str);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
}
|
||||
|
||||
if (check_argc_exact(argc - optind, 3))
|
||||
|
@ -221,7 +221,7 @@ static const char * const cmd_qgroup_assign_usage[] = {
|
|||
static int cmd_qgroup_assign(const struct cmd_struct *cmd,
|
||||
int argc, char **argv)
|
||||
{
|
||||
return _cmd_qgroup_assign(1, argc, argv, cmd_qgroup_assign_usage);
|
||||
return _cmd_qgroup_assign(cmd, 1, argc, argv);
|
||||
}
|
||||
static DEFINE_SIMPLE_COMMAND(qgroup_assign, "assign");
|
||||
|
||||
|
@ -234,7 +234,7 @@ static const char * const cmd_qgroup_remove_usage[] = {
|
|||
static int cmd_qgroup_remove(const struct cmd_struct *cmd,
|
||||
int argc, char **argv)
|
||||
{
|
||||
return _cmd_qgroup_assign(0, argc, argv, cmd_qgroup_remove_usage);
|
||||
return _cmd_qgroup_assign(cmd, 0, argc, argv);
|
||||
}
|
||||
static DEFINE_SIMPLE_COMMAND(qgroup_remove, "remove");
|
||||
|
||||
|
@ -247,7 +247,7 @@ static const char * const cmd_qgroup_create_usage[] = {
|
|||
static int cmd_qgroup_create(const struct cmd_struct *cmd,
|
||||
int argc, char **argv)
|
||||
{
|
||||
clean_args_no_options(argc, argv, cmd_qgroup_create_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
return _cmd_qgroup_create(1, argc, argv);
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ static const char * const cmd_qgroup_destroy_usage[] = {
|
|||
static int cmd_qgroup_destroy(const struct cmd_struct *cmd,
|
||||
int argc, char **argv)
|
||||
{
|
||||
clean_args_no_options(argc, argv, cmd_qgroup_destroy_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
return _cmd_qgroup_create(0, argc, argv);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ static int cmd_quota_enable(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
{
|
||||
int ret;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_quota_enable_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
|
||||
|
||||
|
@ -92,7 +92,7 @@ static int cmd_quota_disable(const struct cmd_struct *cmd,
|
|||
{
|
||||
int ret;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_quota_disable_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv);
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ static int cmd_rescue_zero_log(const struct cmd_struct *cmd,
|
|||
char *devname;
|
||||
int ret;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_rescue_zero_log_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc, 2))
|
||||
return 1;
|
||||
|
@ -227,7 +227,7 @@ static int cmd_rescue_fix_device_size(const struct cmd_struct *cmd,
|
|||
char *devname;
|
||||
int ret;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_rescue_fix_device_size_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc, 2))
|
||||
return 1;
|
||||
|
|
|
@ -1095,8 +1095,7 @@ static int is_scrub_running_in_kernel(int fd,
|
|||
static const char * const cmd_scrub_start_usage[];
|
||||
static const char * const cmd_scrub_resume_usage[];
|
||||
|
||||
static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
|
||||
bool resume)
|
||||
static int scrub_start(int argc, char **argv, bool resume)
|
||||
{
|
||||
int fdmnt;
|
||||
int prg_fd = -1;
|
||||
|
@ -1586,7 +1585,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(cmd, argc, argv, false);
|
||||
return scrub_start(argc, argv, false);
|
||||
}
|
||||
static DEFINE_SIMPLE_COMMAND(scrub_start, "start");
|
||||
|
||||
|
@ -1603,7 +1602,7 @@ static int cmd_scrub_cancel(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
int fdmnt = -1;
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_scrub_cancel_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -1653,7 +1652,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(cmd, argc, argv, true);
|
||||
return scrub_start(argc, argv, true);
|
||||
}
|
||||
static DEFINE_SIMPLE_COMMAND(scrub_resume, "resume");
|
||||
|
||||
|
|
|
@ -792,7 +792,7 @@ static int cmd_subvol_get_default(const struct cmd_struct *cmd,
|
|||
struct btrfs_util_subvolume_info subvol;
|
||||
char *path;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_subvol_get_default_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
return 1;
|
||||
|
@ -854,7 +854,7 @@ static int cmd_subvol_set_default(const struct cmd_struct *cmd,
|
|||
char *path;
|
||||
enum btrfs_util_error err;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_subvol_set_default_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_min(argc - optind, 1) ||
|
||||
check_argc_max(argc - optind, 2))
|
||||
|
@ -895,7 +895,7 @@ static int cmd_subvol_find_new(const struct cmd_struct *cmd,
|
|||
DIR *dirstream = NULL;
|
||||
enum btrfs_util_error err;
|
||||
|
||||
clean_args_no_options(argc, argv, cmd_subvol_find_new_usage);
|
||||
clean_args_no_options(cmd, argc, argv);
|
||||
|
||||
if (check_argc_exact(argc - optind, 2))
|
||||
return 1;
|
||||
|
|
9
help.c
9
help.c
|
@ -85,7 +85,7 @@ int check_argc_max(int nargs, int expected)
|
|||
* Unknown short and long options are reported, optionally the @usage is printed
|
||||
* before exit.
|
||||
*/
|
||||
void clean_args_no_options(int argc, char *argv[], const char * const *usagestr)
|
||||
void clean_args_no_options(const struct cmd_struct *cmd, int argc, char *argv[])
|
||||
{
|
||||
static const struct option long_options[] = {
|
||||
{NULL, 0, NULL, 0}
|
||||
|
@ -99,8 +99,8 @@ void clean_args_no_options(int argc, char *argv[], const char * const *usagestr)
|
|||
|
||||
switch (c) {
|
||||
default:
|
||||
if (usagestr)
|
||||
usage(usagestr);
|
||||
if (cmd->usagestr)
|
||||
usage(cmd->usagestr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,8 @@ void clean_args_no_options(int argc, char *argv[], const char * const *usagestr)
|
|||
* - "-- option1 option2 ..."
|
||||
* - "option1 option2 ..."
|
||||
*/
|
||||
void clean_args_no_options_relaxed(int argc, char *argv[])
|
||||
void clean_args_no_options_relaxed(const struct cmd_struct *cmd,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 1)
|
||||
return;
|
||||
|
|
6
help.h
6
help.h
|
@ -74,8 +74,10 @@ void help_command_group(const struct cmd_group *grp, int argc, char **argv);
|
|||
int check_argc_exact(int nargs, int expected);
|
||||
int check_argc_min(int nargs, int expected);
|
||||
int check_argc_max(int nargs, int expected);
|
||||
void clean_args_no_options(int argc, char *argv[], const char * const *usage);
|
||||
void clean_args_no_options_relaxed(int argc, char *argv[]);
|
||||
void clean_args_no_options(const struct cmd_struct *cmd,
|
||||
int argc, char *argv[]);
|
||||
void clean_args_no_options_relaxed(const struct cmd_struct *cmd,
|
||||
int argc, char *argv[]);
|
||||
|
||||
void fixup_argv0(char **argv, const char *token);
|
||||
void set_argv0(char **argv);
|
||||
|
|
Loading…
Reference in New Issue