add missing --help cli options

- fix typo
- make device online/offline `--help` option consistent

   Old `device online` command
   only recognize `-h` but not the
   long option `--help`; we should make it
   consistent with the `device offline` command

Signed-off-by: Zhai Can <bczhc0@126.com>
This commit is contained in:
Zhai Can 2023-11-17 15:00:47 +08:00
parent a613340b26
commit 2724f8a968
No known key found for this signature in database
GPG Key ID: 41355DA0B11F584F
4 changed files with 74 additions and 22 deletions

View File

@ -66,7 +66,7 @@ int cmd_data_rereplicate(int argc, char *argv[])
static void data_job_usage(void)
{
puts("bcachefs data job\n"
"Usage: bcachefs data job [job} filesystem\n"
"Usage: bcachefs data job [job] filesystem\n"
"\n"
"Kick off a data job and report progress\n"
"\n"

View File

@ -223,15 +223,20 @@ static void device_online_usage(void)
int cmd_device_online(int argc, char *argv[])
{
int opt;
static const struct option longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ NULL }
};
int opt;
while ((opt = getopt(argc, argv, "h")) != -1)
switch (opt) {
case 'h':
device_online_usage();
exit(EXIT_SUCCESS);
}
args_shift(optind);
while ((opt = getopt_long(argc, argv, "h",
longopts, NULL)) != -1)
switch (opt) {
case 'h':
device_online_usage();
exit(EXIT_SUCCESS);
}
args_shift(optind);
char *dev = arg_pop();
if (!dev)
@ -261,7 +266,8 @@ static void device_offline_usage(void)
int cmd_device_offline(int argc, char *argv[])
{
static const struct option longopts[] = {
{ "force", 0, NULL, 'f' },
{ "force", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' },
{ NULL }
};
int opt, flags = 0;

View File

@ -73,22 +73,55 @@ int cmd_unlock(int argc, char *argv[])
return 0;
}
static void set_passphrase_usage(void)
{
puts("bcachefs set-passphrase - Change passphrase on an existing (unmounted) filesystem\n"
"Usage: bcachefs set-passphrase [OPTION]... <device>...\n"
"\n"
"Options:\n"
" -h Display this help and exit\n"
"\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
}
static void remove_passphrase_usage(void)
{
puts("bcachefs remove-passphrase - Remove passphrase on an existing (unmounted) filesystem\n"
"Usage: bcachefs remove-passphrase [OPTION]... <device>...\n"
"\n"
"Options:\n"
" -h Display this help and exit\n"
"\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
}
int cmd_set_passphrase(int argc, char *argv[])
{
struct bch_opts opts = bch2_opts_empty();
struct bch_fs *c;
int opt;
while ((opt = getopt(argc, argv, "h")) != -1)
switch (opt) {
case 'h':
set_passphrase_usage();
exit(EXIT_SUCCESS);
}
args_shift(optind);
if (argc < 2)
die("Please supply one or more devices");
if (!argc) {
set_passphrase_usage();
return EXIT_SUCCESS;
}
opt_set(opts, nostart, true);
struct bch_opts opts = bch2_opts_empty();
struct bch_fs *c;
opt_set(opts, nostart, true);
/*
* we use bch2_fs_open() here, instead of just reading the superblock,
* to make sure we're opening and updating every component device:
*/
c = bch2_fs_open(argv + 1, argc - 1, opts);
c = bch2_fs_open(argv, argc, opts);
if (IS_ERR(c))
die("Error opening %s: %s", argv[1], bch2_err_str(PTR_ERR(c)));
@ -119,14 +152,26 @@ int cmd_set_passphrase(int argc, char *argv[])
int cmd_remove_passphrase(int argc, char *argv[])
{
struct bch_opts opts = bch2_opts_empty();
struct bch_fs *c;
int opt;
while ((opt = getopt(argc, argv, "h")) != -1)
switch (opt) {
case 'h':
remove_passphrase_usage();
exit(EXIT_SUCCESS);
}
args_shift(optind);
if (argc < 2)
die("Please supply one or more devices");
if (!argc) {
remove_passphrase_usage();
return EXIT_SUCCESS;
}
opt_set(opts, nostart, true);
c = bch2_fs_open(argv + 1, argc - 1, opts);
struct bch_opts opts = bch2_opts_empty();
struct bch_fs *c;
opt_set(opts, nostart, true);
c = bch2_fs_open(argv, argc, opts);
if (IS_ERR(c))
die("Error opening %s: %s", argv[1], bch2_err_str(PTR_ERR(c)));

View File

@ -648,6 +648,7 @@ static void migrate_usage(void)
static const struct option migrate_opts[] = {
{ "encrypted", no_argument, NULL, 'e' },
{ "no_passphrase", no_argument, NULL, 'p' },
{ "help", no_argument, NULL, 'h' },
{ NULL }
};