btrfs-progs: pass cmd_struct to usage_unknown_option()

Similar to the other usage helpers, unknown option should also take the
command structure.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2018-03-06 21:54:38 -05:00
parent 91a1476d53
commit 61a7ffc84b
22 changed files with 42 additions and 46 deletions

View File

@ -192,7 +192,7 @@ int main(int argc, char **argv)
usage_command(&btrfs_find_root_cmd, 0, 0);
return 0;
default:
usage_unknown_option(btrfs_find_root_usage, argv);
usage_unknown_option(&btrfs_find_root_cmd, argv);
}
}

View File

@ -587,7 +587,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
background = 1;
break;
default:
usage_unknown_option(cmd_balance_start_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -859,7 +859,7 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
verbose = 1;
break;
default:
usage_unknown_option(cmd_balance_status_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -79,7 +79,7 @@ static int cmd_device_add(const struct cmd_struct *cmd,
force = 1;
break;
default:
usage_unknown_option(cmd_device_add_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -331,7 +331,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
forget = 1;
break;
default:
usage_unknown_option(cmd_device_scan_usage, argv);
usage_unknown_option(cmd, argv);
}
}
devstart = optind;
@ -496,7 +496,7 @@ static int cmd_device_stats(const struct cmd_struct *cmd, int argc, char **argv)
flags = BTRFS_DEV_STATS_RESET;
break;
default:
usage_unknown_option(cmd_device_stats_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -582,7 +582,7 @@ static int cmd_filesystem_du(const struct cmd_struct *cmd,
summarize = 1;
break;
default:
usage_unknown_option(cmd_filesystem_du_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -988,7 +988,7 @@ static int cmd_filesystem_usage(const struct cmd_struct *cmd,
tabular = 1;
break;
default:
usage_unknown_option(cmd_filesystem_usage_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -714,7 +714,7 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
where = BTRFS_SCAN_MOUNTED;
break;
default:
usage_unknown_option(cmd_filesystem_show_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -993,7 +993,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
recursive = 1;
break;
default:
usage_unknown_option(cmd_filesystem_defrag_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -592,7 +592,7 @@ static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
all = 0;
break;
default:
usage_unknown_option(cmd_inspect_dump_super_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -401,7 +401,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
traverse = BTRFS_PRINT_TREE_BFS;
break;
default:
usage_unknown_option(cmd_inspect_dump_tree_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -445,7 +445,7 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
no_pretty = 1;
break;
default:
usage_unknown_option(cmd_inspect_tree_stats_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -106,8 +106,7 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
verbose = 1;
break;
default:
usage_unknown_option(cmd_inspect_inode_resolve_usage,
argv);
usage_unknown_option(cmd, argv);
}
}
@ -170,8 +169,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
size = arg_strtou64(optarg);
break;
default:
usage_unknown_option(cmd_inspect_logical_resolve_usage,
argv);
usage_unknown_option(cmd, argv);
}
}
@ -626,8 +624,7 @@ static int cmd_inspect_min_dev_size(const struct cmd_struct *cmd,
devid = arg_strtou64(optarg);
break;
default:
usage_unknown_option(cmd_inspect_min_dev_size_usage,
argv);
usage_unknown_option(cmd, argv);
}
}
if (check_argc_exact(argc - optind, 1))

View File

@ -272,7 +272,7 @@ static int parse_args(const struct cmd_struct *cmd, int argc, char **argv,
type_str = optarg;
break;
default:
usage_unknown_option(cmd->usagestr, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -68,7 +68,7 @@ static int _cmd_qgroup_assign(const struct cmd_struct *cmd, int assign,
rescan = false;
break;
default:
usage_unknown_option(cmd->usagestr, argv);
usage_unknown_option(cmd, argv);
}
}
} else {
@ -363,7 +363,7 @@ static int cmd_qgroup_show(const struct cmd_struct *cmd, int argc, char **argv)
sync = 1;
break;
default:
usage_unknown_option(cmd_qgroup_show_usage, argv);
usage_unknown_option(cmd, argv);
}
}
btrfs_qgroup_setup_units(unit_mode);
@ -447,7 +447,7 @@ static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
exclusive = 1;
break;
default:
usage_unknown_option(cmd_qgroup_limit_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -135,7 +135,7 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv)
wait_for_completion = 1;
break;
default:
usage_unknown_option(cmd_quota_rescan_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -1352,7 +1352,7 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
dump = 1;
break;
default:
usage_unknown_option(cmd_receive_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -148,7 +148,7 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
force_using_targetdev = 1;
break;
default:
usage_unknown_option(cmd_replace_start_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -348,7 +348,7 @@ static int cmd_replace_status(const struct cmd_struct *cmd,
once = 1;
break;
default:
usage_unknown_option(cmd_replace_status_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -516,7 +516,7 @@ static int cmd_replace_cancel(const struct cmd_struct *cmd,
switch (c) {
case '?':
default:
usage_unknown_option(cmd_replace_cancel_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -64,8 +64,7 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
verbose = 1;
break;
default:
usage_unknown_option(cmd_rescue_chunk_recover_usage,
argv);
usage_unknown_option(cmd, argv);
}
}
@ -135,8 +134,7 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
yes = 1;
break;
default:
usage_unknown_option(cmd_rescue_super_recover_usage,
argv);
usage_unknown_option(cmd, argv);
}
}
if (check_argc_exact(argc - optind, 1))

View File

@ -1527,7 +1527,7 @@ static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv)
get_xattrs = 1;
break;
default:
usage_unknown_option(cmd_restore_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -1171,7 +1171,7 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
force = 1;
break;
default:
usage_unknown_option(cmd->usagestr, argv);
usage_unknown_option(cmd, argv);
}
}
@ -1694,7 +1694,7 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
print_raw = 1;
break;
default:
usage_unknown_option(cmd_scrub_status_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -637,7 +637,7 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
send_flags |= BTRFS_SEND_FLAG_NO_FILE_DATA;
break;
default:
usage_unknown_option(cmd_send_usage, argv);
usage_unknown_option(cmd, argv);
}
}

View File

@ -125,7 +125,7 @@ static int cmd_subvol_create(const struct cmd_struct *cmd,
}
break;
default:
usage_unknown_option(cmd_subvol_create_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -280,7 +280,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
verbose++;
break;
default:
usage_unknown_option(cmd_subvol_delete_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -678,7 +678,7 @@ static int cmd_subvol_snapshot(const struct cmd_struct *cmd,
}
break;
default:
usage_unknown_option(cmd_subvol_snapshot_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -985,7 +985,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv)
by_uuid = 1;
break;
default:
usage_unknown_option(cmd_subvol_show_usage, argv);
usage_unknown_option(cmd, argv);
}
}
@ -1221,7 +1221,7 @@ static int cmd_subvol_sync(const struct cmd_struct *cmd, int argc, char **argv)
}
break;
default:
usage_unknown_option(cmd_subvol_sync_usage, argv);
usage_unknown_option(cmd, argv);
}
}

9
help.c
View File

@ -239,7 +239,7 @@ void usage_command(const struct cmd_struct *cmd, bool full, bool err)
}
__attribute__((noreturn))
void usage_unknown_option(const char * const *usagestr, char **argv)
void usage_unknown_option(const struct cmd_struct *cmd, char **argv)
{
int i;
int c;
@ -251,7 +251,7 @@ void usage_unknown_option(const char * const *usagestr, char **argv)
*/
i = 0;
do {
c = usagestr[0][i];
c = cmd->usagestr[0][i];
if (c == '<' || c == '[' || (prev == ' ' && c == '-')) {
i--;
break;
@ -268,7 +268,7 @@ void usage_unknown_option(const char * const *usagestr, char **argv)
* Try 'btrfs device add --help' for more information
*/
fprintf(stderr, "%.*s: ", i, usagestr[0]);
fprintf(stderr, "%.*s: ", i, cmd->usagestr[0]);
if (!optopt) {
/*
* There's no better way to get the exact unrecognized token
@ -278,7 +278,8 @@ void usage_unknown_option(const char * const *usagestr, char **argv)
} else {
fprintf(stderr, "invalid option '%c'\n", optopt);
}
fprintf(stderr, "Try '%.*s --help' for more information\n", i, usagestr[0]);
fprintf(stderr, "Try '%.*s --help' for more information\n", i,
cmd->usagestr[0]);
exit(1);
}

2
help.h
View File

@ -56,7 +56,7 @@ struct cmd_struct;
struct cmd_group;
__attribute__((noreturn))
void usage_unknown_option(const char * const *usagestr, char **argv);
void usage_unknown_option(const struct cmd_struct *cmd, char **argv);
__attribute__((noreturn))
void usage(const struct cmd_struct *cmd);