Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] zparseopts: improve accuracy of bad-option message
- X-seq: zsh-workers 53299
- From: dana <dana@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] zparseopts: improve accuracy of bad-option message
- Date: Thu, 02 Jan 2025 17:28:46 -0600
- Archived-at: <https://zsh.org/workers/53299>
- Feedback-id: i9be146f9:Fastmail
- List-id: <zsh-workers.zsh.org>
unrelated to my changes from the other week:
() { local -a opts; zparseopts -F -a opts x -foo } -x-foo
(anon):zparseopts: bad option: --foo
this error is misleading: (1) --foo is not a bad option, (2) we (correctly)
didn't even *look* for --foo since we were scanning for stacked options. the
message should reflect this
dana
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 9b2721a09..c12093d0f 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -1976,7 +1976,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
while (*++o) {
if (!(d = sopts[(unsigned char) *o])) {
if (fail) {
- if (*o != '-')
+ if (*o != '-' || o > *pp + 1)
zwarnnam(nam, "bad option: -%c", *o);
else
zwarnnam(nam, "bad option: -%s", o);
diff --git a/Test/V12zparseopts.ztst b/Test/V12zparseopts.ztst
index a2743ea0e..b1abd72d5 100644
--- a/Test/V12zparseopts.ztst
+++ b/Test/V12zparseopts.ztst
@@ -57,7 +57,7 @@
0:zparseopts -D -E
>ret: 0, optv: -a -b 1 -c-d -z, argv: -e
- for 1 in '-a -x -z' '-ax -z' '-a --x -z'; do
+ for 1 in '-a -x -z' '-ax -z' '-a --x -z' -axy -a-xy; do
() {
local -a optv
zparseopts -D -E -F -a optv - a b: c:- z
@@ -71,6 +71,10 @@
>ret: 1, optv: , argv: -ax -z
?(anon):zparseopts:2: bad option: --x
>ret: 1, optv: , argv: -a --x -z
+?(anon):zparseopts:2: bad option: -x
+>ret: 1, optv: , argv: -axy
+?(anon):zparseopts:2: bad option: --
+>ret: 1, optv: , argv: -a-xy
for 1 in '-a 1 2 3' '1 2 3'; do
() {
Messages sorted by:
Reverse Date,
Date,
Thread,
Author