From 2724f8a96870e21a868f8db6c4461fdf56e689f7 Mon Sep 17 00:00:00 2001 From: Zhai Can Date: Fri, 17 Nov 2023 15:00:47 +0800 Subject: [PATCH] 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 --- cmd_data.c | 2 +- cmd_device.c | 24 +++++++++++------- cmd_key.c | 69 ++++++++++++++++++++++++++++++++++++++++++--------- cmd_migrate.c | 1 + 4 files changed, 74 insertions(+), 22 deletions(-) diff --git a/cmd_data.c b/cmd_data.c index 6d709883..2bca4c9e 100644 --- a/cmd_data.c +++ b/cmd_data.c @@ -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" diff --git a/cmd_device.c b/cmd_device.c index 1cb31ab8..3440ee6b 100644 --- a/cmd_device.c +++ b/cmd_device.c @@ -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; diff --git a/cmd_key.c b/cmd_key.c index 96206c4c..7375309b 100644 --- a/cmd_key.c +++ b/cmd_key.c @@ -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]... ...\n" + "\n" + "Options:\n" + " -h Display this help and exit\n" + "\n" + "Report bugs to "); +} + +static void remove_passphrase_usage(void) +{ + puts("bcachefs remove-passphrase - Remove passphrase on an existing (unmounted) filesystem\n" + "Usage: bcachefs remove-passphrase [OPTION]... ...\n" + "\n" + "Options:\n" + " -h Display this help and exit\n" + "\n" + "Report bugs to "); +} + 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))); diff --git a/cmd_migrate.c b/cmd_migrate.c index cde1fce4..4991ec4e 100644 --- a/cmd_migrate.c +++ b/cmd_migrate.c @@ -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 } };