git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] parse-options: typo check for unknown switches
@ 2012-03-03 11:00 René Scharfe
  0 siblings, 0 replies; only message in thread
From: René Scharfe @ 2012-03-03 11:00 UTC (permalink / raw)
  To: git

The user specifies a long option but forgets to type the second
leading dash, we currently detect and report that fact if its first
letter is a valid short option. This is done for safety, to avoid
ambiguity between short options (and their arguments) and a long
option with a missing dash.

This diagnostic message is also helpful for long options whose first
letter is not a valid short option, however. Print it in that case,
too, as a courtesy.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 parse-options.c          |    2 ++
 t/t0040-parse-options.sh |   10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/parse-options.c b/parse-options.c
index 1908996..850cfa7 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -393,6 +393,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 			case -1:
 				return parse_options_usage(ctx, usagestr, options, 1);
 			case -2:
+				if (ctx->opt)
+					check_typos(arg + 1, options);
 				goto unknown;
 			}
 			if (ctx->opt)
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index a44bcb9..e3f354a 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -236,6 +236,16 @@ test_expect_success 'detect possible typos' '
 	test_cmp typo.err output.err
 '
 
+cat > typo.err << EOF
+error: did you mean \`--ambiguous\` (with two dashes ?)
+EOF
+
+test_expect_success 'detect possible typos' '
+	test_must_fail test-parse-options -ambiguous > output 2> output.err &&
+	test ! -s output &&
+	test_cmp typo.err output.err
+'
+
 cat > expect <<EOF
 boolean: 0
 integer: 0
-- 
1.7.9.2

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2012-03-03 11:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-03 11:00 [PATCH] parse-options: typo check for unknown switches René Scharfe

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).