From: Sidong Yang <realwakka@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sidong Yang <realwakka@gmail.com>
Subject: [PATCH] btrfs-progs: help: recognize '--help' option option regardless of its position in arguments
Date: Sat, 5 Oct 2024 06:31:21 +0000 [thread overview]
Message-ID: <20241005063123.257903-1-realwakka@gmail.com> (raw)
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 --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);
}
}
--
2.43.0
reply other threads:[~2024-10-05 8:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241005063123.257903-1-realwakka@gmail.com \
--to=realwakka@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).