diff mbox series

btrfs-progs: help: recognize '--help' option option regardless of its position in arguments

Message ID 20241005063123.257903-1-realwakka@gmail.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: help: recognize '--help' option option regardless of its position in arguments | expand

Commit Message

Sidong Yang Oct. 5, 2024, 6:31 a.m. UTC
Currently, the handle_help_options_next_level() function only checks for
the '--help' option at first. This means that if user provides the
option at no first, the help message is not displayed. This patch
modifies the function to check all arguments for the command.

Issue: #889
Signed-off-by: Sidong Yang <realwakka@gmail.com>
---
 btrfs.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/btrfs.c b/btrfs.c
index d6f441e8..e34a34ab 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -140,19 +140,23 @@  static void check_command_flags(const struct cmd_struct *cmd)
 static void handle_help_options_next_level(const struct cmd_struct *cmd,
 		int argc, char **argv)
 {
+	int i;
 	if (argc < 2)
 		return;
 
-	if (!strcmp(argv[1], "--help")) {
-		if (cmd->next) {
-			argc--;
-			argv++;
-			help_command_group(cmd->next, argc, argv);
-		} else {
-			usage_command(cmd, true, false);
+	for (i=0; i<argc; ++i) {
+		if (!strcmp(argv[i], "--help")) {
+			if (cmd->next) {
+				argc -= i+1;
+				argv += i+1;
+				help_command_group(cmd->next, argc, argv);
+			} else {
+				usage_command(cmd, true, false);
+			}
+
+			exit(0);
 		}
 
-		exit(0);
 	}
 }