Skip to contentSkip to conversation

add help switches

PATCH New Mitchel Humpherys 2 participants 3 messages Jan 16, 2014 – Jan 24, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add help switches

Some -h and --help love.

Mitchel Humpherys (1):
btrfs-progs: add help switches where needed

 btrfs-calc-size.c     | 3 ++-
 btrfs-convert.c       | 3 ++-
 btrfs-corrupt-block.c | 3 ++-
 btrfs-debug-tree.c    | 3 ++-
 btrfs-find-root.c     | 3 ++-
 btrfs-image.c         | 3 ++-
 btrfs-map-logical.c   | 4 +++-
 btrfs-select-super.c  | 3 ++-
 btrfs-show-super.c    | 3 ++-
 btrfs-zero-log.c      | 2 +-
 btrfs.c               | 2 +-
 btrfstune.c           | 3 ++-
 mkfs.c                | 4 +++-
 13 files changed, 26 insertions(+), 13 deletions(-)
Signature · 1 line
Mitch
#1 lore raw

PATCH 1/1 btrfs-progs: add help switches where needed

Some of the btrfs programs don't support -h or --help. It's not really a problem since everyone seems to fall back to printing usage text when an option is not recognized, so passing -h or --help usually gets you the usage text. However, it also usually gets you a "invalid option -- 'h'".

Fix this minor annoyance by adding proper support for -h and --help where appropriate.

---
 btrfs-calc-size.c     | 3 ++-
 btrfs-convert.c       | 3 ++-
 btrfs-corrupt-block.c | 3 ++-
 btrfs-debug-tree.c    | 3 ++-
 btrfs-find-root.c     | 3 ++-
 btrfs-image.c         | 3 ++-
 btrfs-map-logical.c   | 4 +++-
 btrfs-select-super.c  | 3 ++-
 btrfs-show-super.c    | 3 ++-
 btrfs-zero-log.c      | 2 +-
 btrfs.c               | 2 +-
 btrfstune.c           | 3 ++-
 mkfs.c                | 4 +++-
 13 files changed, 26 insertions(+), 13 deletions(-)
btrfs-calc-size.c +2 -1
index a832ee0..6617f4a 100644
@@ -438,7 +438,7 @@ int main(int argc, char **argv)
 	int opt;
 	int ret = 0;
 
-	while ((opt = getopt(argc, argv, "vb")) != -1) {
+	while ((opt = getopt(argc, argv, "vbh")) != -1) {
 		switch (opt) {
 			case 'v':
 				verbose++;
@@ -446,6 +446,7 @@ int main(int argc, char **argv)
 			case 'b':
 				no_pretty = 1;
 				break;
+			case 'h':
 			default:
 				usage();
 				exit(1);
btrfs-convert.c +2 -1
index ae10eed..fb5f1ab 100644
@@ -2704,7 +2704,7 @@ int main(int argc, char *argv[])
 	int rollback = 0;
 	char *file;
 	while(1) {
-		int c = getopt(argc, argv, "dinr");
+		int c = getopt(argc, argv, "dinrh");
 		if (c < 0)
 			break;
 		switch(c) {
@@ -2720,6 +2720,7 @@ int main(int argc, char *argv[])
 			case 'r':
 				rollback = 1;
 				break;
+			case 'h':
 			default:
 				print_usage();
 				return 1;
btrfs-corrupt-block.c +2 -1
index f0c14a9..2765ef7 100644
@@ -720,7 +720,7 @@ int main(int ac, char **av)
 
 	while(1) {
 		int c;
-		c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:", long_options,
+		c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:h", long_options,
 				&option_index);
 		if (c < 0)
 			break;
@@ -787,6 +787,7 @@ int main(int ac, char **av)
 					print_usage();
 				}
 				break;
+			case 'h':
 			default:
 				print_usage();
 		}
btrfs-debug-tree.c +2 -1
index 4a83770..7c1f487 100644
@@ -140,7 +140,7 @@ int main(int ac, char **av)
 
 	while(1) {
 		int c;
-		c = getopt(ac, av, "deb:rRu");
+		c = getopt(ac, av, "deb:rRuh");
 		if (c < 0)
 			break;
 		switch(c) {
@@ -163,6 +163,7 @@ int main(int ac, char **av)
 			case 'b':
 				block_only = atoll(optarg);
 				break;
+			case 'h':
 			default:
 				print_usage();
 		}
btrfs-find-root.c +2 -1
index 7572f52..0680d6a 100644
@@ -286,7 +286,7 @@ int main(int argc, char **argv)
 	int opt;
 	int ret;
 
-	while ((opt = getopt(argc, argv, "l:o:g:")) != -1) {
+	while ((opt = getopt(argc, argv, "l:o:g:h")) != -1) {
 		switch(opt) {
 			errno = 0;
 			case 'o':
@@ -315,6 +315,7 @@ int main(int argc, char **argv)
 					exit(1);
 				}
 				break;
+			case 'h':
 			default:
 				usage();
 				exit(1);
btrfs-image.c +2 -1
index 7bcfc06..98f5864 100644
@@ -2475,7 +2475,7 @@ int main(int argc, char *argv[])
 	FILE *out;
 
 	while (1) {
-		int c = getopt(argc, argv, "rc:t:oswm");
+		int c = getopt(argc, argv, "rc:t:oswmh");
 		if (c < 0)
 			break;
 		switch (c) {
@@ -2505,6 +2505,7 @@ int main(int argc, char *argv[])
 			create = 0;
 			multi_devices = 1;
 			break;
+		case 'h':
 		default:
 			print_usage();
 		}
btrfs-map-logical.c +3 -1
index 51179a3..da8d896 100644
@@ -107,6 +107,7 @@ static struct option long_options[] = {
 	{ "copy", 1, NULL, 'c' },
 	{ "output", 1, NULL, 'o' },
 	{ "bytes", 1, NULL, 'b' },
+	{ "help", 0, NULL, 'h' },
 	{ NULL, 0, NULL, 0}
 };
 
@@ -126,7 +127,7 @@ int main(int ac, char **av)
 
 	while(1) {
 		int c;
-		c = getopt_long(ac, av, "l:c:o:b:", long_options,
+		c = getopt_long(ac, av, "l:c:o:b:h", long_options,
 				&option_index);
 		if (c < 0)
 			break;
@@ -158,6 +159,7 @@ int main(int ac, char **av)
 			case 'o':
 				output_file = strdup(optarg);
 				break;
+			case 'h':
 			default:
 				print_usage();
 		}
btrfs-select-super.c +2 -1
index 6a458b8..18ae7b2 100644
@@ -48,7 +48,7 @@ int main(int ac, char **av)
 
 	while(1) {
 		int c;
-		c = getopt(ac, av, "s:");
+		c = getopt(ac, av, "s:h");
 		if (c < 0)
 			break;
 		switch(c) {
@@ -56,6 +56,7 @@ int main(int ac, char **av)
 				num = atol(optarg);
 				bytenr = btrfs_sb_offset(num);
 				break;
+			case 'h':
 			default:
 				print_usage();
 		}
btrfs-show-super.c +2 -1
index 0c3c73c..225cb84 100644
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
 	int arg, i;
 	u64 sb_bytenr = btrfs_sb_offset(0);
 
-	while ((opt = getopt(argc, argv, "ai:")) != -1) {
+	while ((opt = getopt(argc, argv, "ai:h")) != -1) {
 		switch (opt) {
 		case 'i':
 			arg = atoi(optarg);
@@ -81,6 +81,7 @@ int main(int argc, char **argv)
 			all = 1;
 			break;
 
+		case 'h':
 		default:
 			print_usage();
 			exit(1);
btrfs-zero-log.c +1 -1
index ab7f418..4ae468c 100644
@@ -46,7 +46,7 @@ int main(int ac, char **av)
 	struct btrfs_trans_handle *trans;
 	int ret;
 
-	if (ac != 2)
+	if (ac != 2 || !strcmp(av[1], "--help") || !strcmp(av[1], "-h"))
 		print_usage();
 
 	radix_tree_init();
btrfs.c +1 -1
index d5fc738..7ca4427 100644
@@ -112,7 +112,7 @@ static void handle_help_options_next_level(const struct cmd_struct *cmd,
 	if (argc < 2)
 		return;
 
-	if (!strcmp(argv[1], "--help")) {
+	if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
 		if (cmd->next) {
 			argc--;
 			argv++;
btrfstune.c +2 -1
index 50724ba..47077f5 100644
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
 	int ret;
 
 	while(1) {
-		int c = getopt(argc, argv, "S:rx");
+		int c = getopt(argc, argv, "S:rxh");
 		if (c < 0)
 			break;
 		switch(c) {
@@ -130,6 +130,7 @@ int main(int argc, char *argv[])
 		case 'x':
 			skinny_flag = 1;
 			break;
+		case 'h':
 		default:
 			print_usage();
 			return 1;
mkfs.c +3 -1
index 33369f9..f475b5d 100644
@@ -350,6 +350,7 @@ static struct option long_options[] = {
 	{ "rootdir", 1, NULL, 'r' },
 	{ "nodiscard", 0, NULL, 'K' },
 	{ "features", 0, NULL, 'O' },
+	{ "help", 0, NULL, 'h' },
 	{ NULL, 0, NULL, 0}
 };
 
@@ -1264,7 +1265,7 @@ int main(int ac, char **av)
 
 	while(1) {
 		int c;
-		c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:VMK",
+		c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:VMKh",
 				long_options, &option_index);
 		if (c < 0)
 			break;
@@ -1336,6 +1337,7 @@ int main(int ac, char **av)
 			case 'K':
 				discard = 0;
 				break;
+			case 'h':
 			default:
 				print_usage();
 		}
Signature · 1 line
Mitch
#2 lore raw

Re: [PATCH] btrfs-progs: add help switches where needed

Quoted 7 lines · Mitchel Humpherys

Some of the btrfs programs don't support -h or --help. It's not really a problem since everyone seems to fall back to printing usage text when an option is not recognized, so passing -h or --help usually gets you the usage text. However, it also usually gets you a "invalid option -- 'h'".

Fix this minor annoyance by adding proper support for -h and --help where appropriate.

There was patch to add -h option, to fsck only as an example, and so far I don't think we need it for any command, when there's --help available.

http://www.spinics.net/lists/linux-btrfs/msg29110.html

As you say, it's a minor annoyance, I'd prefer to not use the -h option.

david