{"thread":{"id":"29820","subject":"[PATCH] parse-options: typo check for unknown switches","startedAt":"2012-03-03T11:00:29Z","lastAt":"2012-03-03T11:00:29Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"185983","messageId":"4F51F9CD.9010904@lsrfire.ath.cx","threadId":"29820","inReplyTo":null,"subject":"[PATCH] parse-options: typo check for unknown switches","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2012-03-03T11:00:29Z","receivedAt":"2012-03-03T11:00:29Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"The user specifies a long option but forgets to type the second\nleading dash, we currently detect and report that fact if its first\nletter is a valid short option. This is done for safety, to avoid\nambiguity between short options (and their arguments) and a long\noption with a missing dash.\n\nThis diagnostic message is also helpful for long options whose first\nletter is not a valid short option, however. Print it in that case,\ntoo, as a courtesy.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n parse-options.c          |    2 ++\n t/t0040-parse-options.sh |   10 ++++++++++\n 2 files changed, 12 insertions(+)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 1908996..850cfa7 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -393,6 +393,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\t\tcase -1:\n \t\t\t\treturn parse_options_usage(ctx, usagestr, options, 1);\n \t\t\tcase -2:\n+\t\t\t\tif (ctx->opt)\n+\t\t\t\t\tcheck_typos(arg + 1, options);\n \t\t\t\tgoto unknown;\n \t\t\t}\n \t\t\tif (ctx->opt)\ndiff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh\nindex a44bcb9..e3f354a 100755\n--- a/t/t0040-parse-options.sh\n+++ b/t/t0040-parse-options.sh\n@@ -236,6 +236,16 @@ test_expect_success 'detect possible typos' '\n \ttest_cmp typo.err output.err\n '\n \n+cat > typo.err << EOF\n+error: did you mean \\`--ambiguous\\` (with two dashes ?)\n+EOF\n+\n+test_expect_success 'detect possible typos' '\n+\ttest_must_fail test-parse-options -ambiguous > output 2> output.err &&\n+\ttest ! -s output &&\n+\ttest_cmp typo.err output.err\n+'\n+\n cat > expect <<EOF\n boolean: 0\n integer: 0\n-- \n1.7.9.2\n"}]}