Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] getopts: Accurately report '-x' or '+x' in error messages



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