Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Improve error message from zparseopts -F
- X-seq: zsh-workers 47899
- From: Joshua Krusell <js.shirin@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: Joshua Krusell <js.shirin@xxxxxxxxx>
- Subject: [PATCH] Improve error message from zparseopts -F
- Date: Tue, 2 Feb 2021 23:17:28 +0100
- Archived-at: <https://zsh.org/workers/47899>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-02/20210202221728.371739-1-js.shirin%40gmail.com>
- List-id: <zsh-workers.zsh.org>
When encountering an option not described by the specs, `zparseopts -F`
prints an error message with the first character following the leading
'-'. This works great for short options, but for long options it leads
to the uninformative message "bad option: -".
---
I see that this was the original intended behaviour in the V12zparseopts
tests, so ignore if I've missed something.
/Joshua
Src/Modules/zutil.c | 5 ++++-
Test/V12zparseopts.ztst | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 5c96d06c1..c8017d0c0 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -1873,7 +1873,10 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
while (*++o) {
if (!(d = sopts[STOUC(*o)])) {
if (fail) {
- zwarnnam(nam, "bad option: %c", *o);
+ if (*o != '-')
+ zwarnnam(nam, "bad option: %c", *o);
+ else
+ zwarnnam(nam, "bad option: %s", o);
return 1;
}
o = NULL;
diff --git a/Test/V12zparseopts.ztst b/Test/V12zparseopts.ztst
index d7fc33f72..c41c49022 100644
--- a/Test/V12zparseopts.ztst
+++ b/Test/V12zparseopts.ztst
@@ -69,7 +69,7 @@
>ret: 1, optv: , argv: -a -x -z
?(anon):zparseopts:2: bad option: x
>ret: 1, optv: , argv: -ax -z
-?(anon):zparseopts:2: bad option: -
+?(anon):zparseopts:2: bad option: -x
>ret: 1, optv: , argv: -a --x -z
for 1 in '-a 1 2 3' '1 2 3'; do
--
2.30.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author