Add --quiet to cmd_format

This commit is contained in:
Kent Overstreet 2017-03-14 11:41:29 -08:00
parent d252e12acc
commit d4e6736e59

View File

@ -54,7 +54,8 @@ x(0, discard, NULL, NULL) \
t("Device specific options must come before corresponding devices, e.g.") \ t("Device specific options must come before corresponding devices, e.g.") \
t(" bcache format --tier 0 /dev/sdb --tier 1 /dev/sdc") \ t(" bcache format --tier 0 /dev/sdb --tier 1 /dev/sdc") \
t("") \ t("") \
x('h', help, NULL, "display this help and exit") x('q', quiet, NULL, "Only print errors") \
x('h', help, NULL, "Display this help and exit")
static void usage(void) static void usage(void)
{ {
@ -90,6 +91,7 @@ static void usage(void)
" --discard Enable discards\n" " --discard Enable discards\n"
" -t, --tier=# Higher tier (e.g. 1) indicates slower devices\n" " -t, --tier=# Higher tier (e.g. 1) indicates slower devices\n"
"\n" "\n"
" -q, --quiet Only print errors\n"
" -h, --help Display this help and exit\n" " -h, --help Display this help and exit\n"
"\n" "\n"
"Device specific options must come before corresponding devices, e.g.\n" "Device specific options must come before corresponding devices, e.g.\n"
@ -126,13 +128,13 @@ int cmd_format(int argc, char *argv[])
darray(struct dev_opts) devices; darray(struct dev_opts) devices;
struct format_opts opts = format_opts_default(); struct format_opts opts = format_opts_default();
struct dev_opts dev_opts = { 0 }, *dev; struct dev_opts dev_opts = { 0 }, *dev;
bool force = false, no_passphrase = false; bool force = false, no_passphrase = false, quiet = false;
int opt; int opt;
darray_init(devices); darray_init(devices);
while ((opt = getopt_long(argc, argv, while ((opt = getopt_long(argc, argv,
"-b:e:L:U:ft:h", "-b:e:L:U:ft:qh",
format_opts, format_opts,
NULL)) != -1) NULL)) != -1)
switch (opt) { switch (opt) {
@ -224,6 +226,10 @@ int cmd_format(int argc, char *argv[])
darray_append(devices, dev_opts); darray_append(devices, dev_opts);
dev_opts.size = 0; dev_opts.size = 0;
break; break;
case O_quiet:
case 'q':
quiet = true;
break;
case O_help: case O_help:
case 'h': case 'h':
usage(); usage();
@ -258,7 +264,9 @@ int cmd_format(int argc, char *argv[])
struct bch_sb *sb = struct bch_sb *sb =
bcache_format(opts, devices.item, darray_size(devices)); bcache_format(opts, devices.item, darray_size(devices));
bcache_super_print(sb, HUMAN_READABLE);
if (!quiet)
bcache_super_print(sb, HUMAN_READABLE);
free(sb); free(sb);
if (opts.passphrase) { if (opts.passphrase) {