diff --git a/cmds-balance.c b/cmds-balance.c index b4f49e7a..dc8957b4 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -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; diff --git a/cmds-device.c b/cmds-device.c index 29b547ed..b1966d7b 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -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; diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 80d84831..4e7a3ee1 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -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)) diff --git a/cmds-inspect.c b/cmds-inspect.c index 669d2684..fa99f7ea 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -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; diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 5a6dbc88..e51e47a9 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -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); } diff --git a/cmds-quota.c b/cmds-quota.c index 2e88e1fd..c3899a23 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -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); diff --git a/cmds-rescue.c b/cmds-rescue.c index b6682ad3..53673236 100644 --- a/cmds-rescue.c +++ b/cmds-rescue.c @@ -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; diff --git a/cmds-scrub.c b/cmds-scrub.c index 39797bd3..d9ef66dd 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -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"); diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 9683710b..a857db88 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -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; diff --git a/help.c b/help.c index af7a4255..71665f9e 100644 --- a/help.c +++ b/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; diff --git a/help.h b/help.h index 6920d6c3..416bc051 100644 --- a/help.h +++ b/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);