zsh-workers
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: zsh-workers@zsh.org
Subject: [PATCH] getopts: Accurately report '-x' or '+x' in error messages
Date: Fri, 1 Dec 2017 01:12:15 -0600	[thread overview]
Message-ID: <733779CE-86B9-4178-B38B-7E64390BB4C6@dana.is> (raw)

Related to zsh-workers 40010:

getopts error messages about illegal options or missing values always reference
the -x variant of the option, even if the +x one was used instead. The included
patch simply makes it report the correct prefix.

PS: There are a few other places in the code where it seems that the - prefix is
hard-coded into the error message, but i didn't actually check to see if that
was a problem. This patch in addition to the previous one should cover most
cases people are likely to run into, though, i'd think.

PPS: I didn't add any tests because there aren't any for getopts — let me know
if you'd like me to create some.

dana


diff --git a/Src/builtin.c b/Src/builtin.c
index 0ff9e4f16..f002b9912 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5442,8 +5442,9 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
	if(quiet) {
	    zoptarg = metafy(optbuf, lenoptbuf, META_DUP);
	} else {
-	    zwarn(*p == '?' ? "bad option: -%c" :
-		  "argument expected after -%c option", opch);
+	    zwarn(*p == '?' ? "bad option: %c%c" :
+		  "argument expected after %c%c option",
+		  "?-+"[lenoptbuf], opch);
	    zoptarg=ztrdup("");
	}
	return 0;


             reply	other threads:[~2017-12-01  7:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20171201071310epcas1p4e06bf3264433a5d7318fbb9d6c594c18@epcas1p4.samsung.com>
2017-12-01  7:12 ` dana [this message]
2017-12-01  9:20   ` Peter Stephenson
2017-12-01  9:39     ` dana
2017-12-01  9:48       ` Peter Stephenson

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=733779CE-86B9-4178-B38B-7E64390BB4C6@dana.is \
    --to=dana@dana.is \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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