public inbox for gwml@vger.gnuweeb.org
 help / color / mirror / Atom feed
From: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH gwproxy v1 2/2] gwproxy: Show help on invalid parameter
Date: Thu, 31 Jul 2025 07:27:24 +0700	[thread overview]
Message-ID: <20250731002724.294967-3-alviro.iskandar@gnuweeb.org> (raw)
In-Reply-To: <20250731002724.294967-1-alviro.iskandar@gnuweeb.org>

When gwproxy is run with a zero argument (or argc=1), it doesn't show a
helpful message, just like this:

  Error: --target is required unless --as-socks5 is specified.

Show the help when the argument is invalid to let new users get better
experience.

Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
---
 src/gwproxy/gwproxy.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/gwproxy/gwproxy.c b/src/gwproxy/gwproxy.c
index c5283a9..dac9903 100644
--- a/src/gwproxy/gwproxy.c
+++ b/src/gwproxy/gwproxy.c
@@ -230,25 +230,30 @@ static int parse_options(int argc, char *argv[], struct gwp_cfg *cfg)
 
 	if (!cfg->as_socks5 && !cfg->target) {
 		fprintf(stderr, "Error: --target is required unless --as-socks5 is specified.\n");
-		return -EINVAL;
+		goto einval;
 	}
 
 	if (cfg->nr_workers <= 0) {
 		fprintf(stderr, "Error: --nr-workers must be at least 1.\n");
-		return -EINVAL;
+		goto einval;
 	}
 
 	if (cfg->target_buf_size <= 1) {
 		fprintf(stderr, "Error: --target-buf-size must be greater than 1.\n");
-		return -EINVAL;
+		goto einval;
 	}
 
 	if (cfg->client_buf_size <= 1) {
 		fprintf(stderr, "Error: --client-buf-size must be greater than 1.\n");
-		return -EINVAL;
+		goto einval;
 	}
 
 	return 0;
+
+einval:
+	fprintf(stderr, "\n");
+	show_help(argv[0]);
+	return -EINVAL;
 }
 
 #define FULL_ADDRSTRLEN (INET6_ADDRSTRLEN + sizeof(":65535[]") - 1)
-- 
Alviro Iskandar Setiawan


  parent reply	other threads:[~2025-07-31  0:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31  0:27 [PATCH gwproxy v1 0/2] Auth-file hot reload and show help message for invalid parameters Alviro Iskandar Setiawan
2025-07-31  0:27 ` [PATCH gwproxy v1 1/2] io_uring: Add auth-file hot reload support Alviro Iskandar Setiawan
2025-07-31  0:27 ` Alviro Iskandar Setiawan [this message]
2025-07-31  0:29 ` [PATCH gwproxy v1 0/2] Auth-file hot reload and show help message for invalid parameters Ammar Faizi

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=20250731002724.294967-3-alviro.iskandar@gnuweeb.org \
    --to=alviro.iskandar@gnuweeb.org \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=gwml@vger.gnuweeb.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