Skip to content

Commit 4ac63cc

Browse files
committed
btrfs-progs: help: don't print usage on wrong argument counts
The error message about the unsatisfied argument count is scrolled away by the full usage string dump. This is not considered a good usability practice. This commit switches all direct usage -> return patterns, where the argument check has no other constraint, eg. dependency on an option. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 4ac4463 commit 4ac63cc

23 files changed

+66
-69
lines changed

btrfs-corrupt-block.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ int main(int argc, char **argv)
12351235
}
12361236
set_argv0(argv);
12371237
if (check_argc_min(argc - optind, 1))
1238-
print_usage(1);
1238+
return 1;
12391239
dev = argv[optind];
12401240

12411241
radix_tree_init();

btrfs-crc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ int main(int argc, char **argv)
7070

7171
if (!loop) {
7272
if (check_argc_exact(argc - optind, 1))
73-
print_usage(255);
73+
return 1;
7474

7575
printf("%12u - %s\n", crc32c(~1, str, strlen(str)), str);
7676
return 0;
7777
}
7878
if (check_argc_exact(argc - optind, 0))
79-
print_usage(255);
79+
return 1;
8080

8181
buf = malloc(length);
8282
if (!buf)

btrfs-fragments.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ int main(int argc, char **argv)
442442

443443
set_argv0(argv);
444444
if (check_argc_min(argc - optind, 1))
445-
fragments_usage();
445+
return 1;
446446

447447
path = argv[optind++];
448448

btrfs-map-logical.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int main(int argc, char **argv)
252252
}
253253
set_argv0(argv);
254254
if (check_argc_min(argc - optind, 1))
255-
print_usage();
255+
return 1;
256256
if (logical == 0)
257257
print_usage();
258258

btrfs-select-super.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(int argc, char **argv)
6767
}
6868
set_argv0(argv);
6969
if (check_argc_exact(argc - optind, 1))
70-
print_usage();
70+
return 1;
7171

7272
if (bytenr == 0) {
7373
fprintf(stderr, "Please select the super copy with -s\n");

btrfstune.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,8 @@ int main(int argc, char *argv[])
547547

548548
set_argv0(argv);
549549
device = argv[optind];
550-
if (check_argc_exact(argc - optind, 1)) {
551-
print_usage();
550+
if (check_argc_exact(argc - optind, 1))
552551
return 1;
553-
}
554552

555553
if (random_fsid && new_fsid_str) {
556554
error("random fsid can't be used with specified fsid");

cmds-balance.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static int cmd_balance_start(int argc, char **argv)
591591
}
592592

593593
if (check_argc_exact(argc - optind, 1))
594-
usage(cmd_balance_start_usage);
594+
return 1;
595595

596596
/*
597597
* allow -s only under --force, otherwise do with system chunks
@@ -691,7 +691,7 @@ static int cmd_balance_pause(int argc, char **argv)
691691
clean_args_no_options(argc, argv, cmd_balance_pause_usage);
692692

693693
if (check_argc_exact(argc - optind, 1))
694-
usage(cmd_balance_pause_usage);
694+
return 1;
695695

696696
path = argv[optind];
697697

@@ -729,7 +729,7 @@ static int cmd_balance_cancel(int argc, char **argv)
729729
clean_args_no_options(argc, argv, cmd_balance_cancel_usage);
730730

731731
if (check_argc_exact(argc - optind, 1))
732-
usage(cmd_balance_cancel_usage);
732+
return 1;
733733

734734
path = argv[optind];
735735

@@ -768,7 +768,7 @@ static int cmd_balance_resume(int argc, char **argv)
768768
clean_args_no_options(argc, argv, cmd_balance_resume_usage);
769769

770770
if (check_argc_exact(argc - optind, 1))
771-
usage(cmd_balance_resume_usage);
771+
return 1;
772772

773773
path = argv[optind];
774774

@@ -855,7 +855,7 @@ static int cmd_balance_status(int argc, char **argv)
855855
}
856856

857857
if (check_argc_exact(argc - optind, 1))
858-
usage(cmd_balance_status_usage);
858+
return 1;
859859

860860
path = argv[optind];
861861

cmds-device.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int cmd_device_add(int argc, char **argv)
8383
}
8484

8585
if (check_argc_min(argc - optind, 2))
86-
usage(cmd_device_add_usage);
86+
return 1;
8787

8888
last_dev = argc - 1;
8989
mntpnt = argv[last_dev];
@@ -153,7 +153,7 @@ static int _cmd_device_remove(int argc, char **argv,
153153
clean_args_no_options(argc, argv, usagestr);
154154

155155
if (check_argc_min(argc - optind, 2))
156-
usage(usagestr);
156+
return 1;
157157

158158
mntpnt = argv[argc - 1];
159159

@@ -405,7 +405,7 @@ static int cmd_device_ready(int argc, char **argv)
405405
clean_args_no_options(argc, argv, cmd_device_ready_usage);
406406

407407
if (check_argc_exact(argc - optind, 1))
408-
usage(cmd_device_ready_usage);
408+
return 1;
409409

410410
fd = open("/dev/btrfs-control", O_RDWR);
411411
if (fd < 0) {
@@ -492,7 +492,7 @@ static int cmd_device_stats(int argc, char **argv)
492492
}
493493

494494
if (check_argc_exact(argc - optind, 1))
495-
usage(cmd_device_stats_usage);
495+
return 1;
496496

497497
dev_path = argv[optind];
498498

@@ -629,7 +629,7 @@ static int cmd_device_usage(int argc, char **argv)
629629
clean_args_no_options(argc, argv, cmd_device_usage_usage);
630630

631631
if (check_argc_min(argc - optind, 1))
632-
usage(cmd_device_usage_usage);
632+
return 1;
633633

634634
for (i = optind; i < argc; i++) {
635635
int fd;

cmds-fi-du.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ int cmd_filesystem_du(int argc, char **argv)
586586
}
587587

588588
if (check_argc_min(argc - optind, 1))
589-
usage(cmd_filesystem_du_usage);
589+
return 1;
590590

591591
kernel_version = get_running_kernel_version();
592592

cmds-fi-usage.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ int cmd_filesystem_usage(int argc, char **argv)
992992
}
993993

994994
if (check_argc_min(argc - optind, 1))
995-
usage(cmd_filesystem_usage_usage);
995+
return 1;
996996

997997
for (i = optind; i < argc; i++) {
998998
int fd;

cmds-filesystem.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int cmd_filesystem_df(int argc, char **argv)
131131
clean_args_no_options(argc, argv, cmd_filesystem_df_usage);
132132

133133
if (check_argc_exact(argc - optind, 1))
134-
usage(cmd_filesystem_df_usage);
134+
return 1;
135135

136136
path = argv[optind];
137137

@@ -713,7 +713,7 @@ static int cmd_filesystem_show(int argc, char **argv)
713713
}
714714

715715
if (check_argc_max(argc, optind + 1))
716-
usage(cmd_filesystem_show_usage);
716+
return 1;
717717

718718
if (argc > optind) {
719719
search = argv[optind];
@@ -824,7 +824,7 @@ static int cmd_filesystem_sync(int argc, char **argv)
824824
clean_args_no_options(argc, argv, cmd_filesystem_sync_usage);
825825

826826
if (check_argc_exact(argc - optind, 1))
827-
usage(cmd_filesystem_sync_usage);
827+
return 1;
828828

829829
err = btrfs_util_sync(argv[optind]);
830830
if (err) {
@@ -970,7 +970,7 @@ static int cmd_filesystem_defrag(int argc, char **argv)
970970
}
971971

972972
if (check_argc_min(argc - optind, 1))
973-
usage(cmd_filesystem_defrag_usage);
973+
return 1;
974974

975975
memset(&defrag_global_range, 0, sizeof(defrag_global_range));
976976
defrag_global_range.start = start;
@@ -1094,7 +1094,7 @@ static int cmd_filesystem_resize(int argc, char **argv)
10941094
clean_args_no_options_relaxed(argc, argv);
10951095

10961096
if (check_argc_exact(argc - optind, 2))
1097-
usage(cmd_filesystem_resize_usage);
1097+
return 1;
10981098

10991099
amount = argv[optind];
11001100
path = argv[optind + 1];
@@ -1166,7 +1166,7 @@ static int cmd_filesystem_label(int argc, char **argv)
11661166

11671167
if (check_argc_min(argc - optind, 1) ||
11681168
check_argc_max(argc - optind, 2))
1169-
usage(cmd_filesystem_label_usage);
1169+
return 1;
11701170

11711171
if (argc - optind > 1) {
11721172
return set_label(argv[optind], argv[optind + 1]);

cmds-inspect-dump-super.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ int cmd_inspect_dump_super(int argc, char **argv)
596596
}
597597

598598
if (check_argc_min(argc - optind, 1))
599-
usage(cmd_inspect_dump_super_usage);
599+
return 1;
600600

601601
for (i = optind; i < argc; i++) {
602602
filename = argv[i];

cmds-inspect-dump-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
319319
}
320320

321321
if (check_argc_exact(argc - optind, 1))
322-
usage(cmd_inspect_dump_tree_usage);
322+
return 1;
323323

324324
ret = check_arg_type(argv[optind]);
325325
if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {

cmds-inspect-tree-stats.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,8 @@ int cmd_inspect_tree_stats(int argc, char **argv)
448448
}
449449
}
450450

451-
if (check_argc_exact(argc - optind, 1)) {
452-
usage(cmd_inspect_tree_stats_usage);
453-
}
451+
if (check_argc_exact(argc - optind, 1))
452+
return 1;
454453

455454
ret = check_mounted(argv[optind]);
456455
if (ret < 0) {

cmds-inspect.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int cmd_inspect_inode_resolve(int argc, char **argv)
111111
}
112112

113113
if (check_argc_exact(argc - optind, 2))
114-
usage(cmd_inspect_inode_resolve_usage);
114+
return 1;
115115

116116
fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1);
117117
if (fd < 0)
@@ -173,7 +173,7 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
173173
}
174174

175175
if (check_argc_exact(argc - optind, 2))
176-
usage(cmd_inspect_logical_resolve_usage);
176+
return 1;
177177

178178
size = min(size, (u64)SZ_64K);
179179
inodes = malloc(size);
@@ -281,7 +281,7 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv)
281281
clean_args_no_options(argc, argv, cmd_inspect_subvolid_resolve_usage);
282282

283283
if (check_argc_exact(argc - optind, 2))
284-
usage(cmd_inspect_subvolid_resolve_usage);
284+
return 1;
285285

286286
fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1);
287287
if (fd < 0) {
@@ -322,7 +322,7 @@ static int cmd_inspect_rootid(int argc, char **argv)
322322
clean_args_no_options(argc, argv, cmd_inspect_rootid_usage);
323323

324324
if (check_argc_exact(argc - optind, 1))
325-
usage(cmd_inspect_rootid_usage);
325+
return 1;
326326

327327
fd = btrfs_open_file_or_dir(argv[optind], &dirstream, 1);
328328
if (fd < 0) {
@@ -622,7 +622,7 @@ static int cmd_inspect_min_dev_size(int argc, char **argv)
622622
}
623623
}
624624
if (check_argc_exact(argc - optind, 1))
625-
usage(cmd_inspect_min_dev_size_usage);
625+
return 1;
626626

627627
fd = btrfs_open_dir(argv[optind], &dirstream, 1);
628628
if (fd < 0) {

cmds-property.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static void parse_args(int argc, char **argv,
289289

290290
if (check_argc_min(argc - optind, min_nonopt_args) ||
291291
check_argc_max(argc - optind, max_nonopt_args))
292-
usage(usage_str);
292+
exit(1);
293293

294294
*types = 0;
295295
if (type_str) {

cmds-qgroup.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static int _cmd_qgroup_assign(int assign, int argc, char **argv,
7777
}
7878

7979
if (check_argc_exact(argc - optind, 3))
80-
usage(usage_str);
80+
return 1;
8181

8282
memset(&args, 0, sizeof(args));
8383
args.assign = assign;
@@ -367,7 +367,7 @@ static int cmd_qgroup_show(int argc, char **argv)
367367
btrfs_qgroup_setup_units(unit_mode);
368368

369369
if (check_argc_exact(argc - optind, 1))
370-
usage(cmd_qgroup_show_usage);
370+
return 1;
371371

372372
path = argv[optind];
373373
fd = btrfs_open_dir(path, &dirstream, 1);
@@ -449,7 +449,7 @@ static int cmd_qgroup_limit(int argc, char **argv)
449449
}
450450

451451
if (check_argc_min(argc - optind, 2))
452-
usage(cmd_qgroup_limit_usage);
452+
return 1;
453453

454454
if (!parse_limit(argv[optind], &size)) {
455455
error("invalid size argument: %s", argv[optind]);

cmds-quota.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int cmd_quota_rescan(int argc, char **argv)
142142
}
143143

144144
if (check_argc_exact(argc - optind, 1))
145-
usage(cmd_quota_rescan_usage);
145+
return 1;
146146

147147
memset(&args, 0, sizeof(args));
148148

cmds-replace.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int cmd_replace_start(int argc, char **argv)
156156
BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID :
157157
BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS;
158158
if (check_argc_exact(argc - optind, 3))
159-
usage(cmd_replace_start_usage);
159+
return 1;
160160
path = argv[optind + 2];
161161

162162
fdmnt = open_path_or_dev_mnt(path, &dirstream, 1);
@@ -350,7 +350,7 @@ static int cmd_replace_status(int argc, char **argv)
350350
}
351351

352352
if (check_argc_exact(argc - optind, 1))
353-
usage(cmd_replace_status_usage);
353+
return 1;
354354

355355
path = argv[optind];
356356
fd = btrfs_open_dir(path, &dirstream, 1);
@@ -516,7 +516,7 @@ static int cmd_replace_cancel(int argc, char **argv)
516516
}
517517

518518
if (check_argc_exact(argc - optind, 1))
519-
usage(cmd_replace_cancel_usage);
519+
return 1;
520520

521521
path = argv[optind];
522522
fd = btrfs_open_dir(path, &dirstream, 1);

0 commit comments

Comments
 (0)