Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] getopts: Accurately report '-x' or '+x' in error messages
- X-seq: zsh-workers 42063
- From: dana <dana@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] getopts: Accurately report '-x' or '+x' in error messages
- Date: Fri, 1 Dec 2017 01:12:15 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=Ce3TwUZZQuaglH2ZEw1dc5QAbZUaucl8swRLYXIF1E4=; b=y///DGNQlHMMUNGxwPkcGetSaPyoFMnYPyjrSedhkp24K7ulvFcRT9Ay8qcRwn+wkx qCvLgQO8S3nyk3fbAqPQtRhXBdOgDb41WMSEQWANV3Jml9kJuGJslOkeL67YPbpYcWfg rKS3Mx5il7Asa0mEdaamC1KJVXfxqxYKQTrhzk74GBbCYyVboLSFqqupe8S01v4p3fiP XXoOmiEVv6HMdg3aMvjsbtJi4hLNKe9mzR0hMZd/n1sWczzncA2b0LJJh92F7eiPR0FW ym1X5lnXyNl7wGRnaeMSZDm69JkWrMneCgoy2rXrH6NmpPlZMgOkgfkqvbgtSsziEzX/ 6QAg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author