zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Improve error message from zparseopts -F
@ 2021-02-02 22:17 Joshua Krusell
  2021-02-03 11:28 ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Joshua Krusell @ 2021-02-02 22:17 UTC (permalink / raw)
  To: zsh-workers; +Cc: Joshua Krusell

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Improve error message from zparseopts -F
  2021-02-02 22:17 [PATCH] Improve error message from zparseopts -F Joshua Krusell
@ 2021-02-03 11:28 ` Daniel Shahaf
  2021-02-03 11:36   ` Peter Stephenson
  2021-02-03 15:06   ` Joshua Krusell
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Shahaf @ 2021-02-03 11:28 UTC (permalink / raw)
  To: Joshua Krusell; +Cc: zsh-workers

Joshua Krusell wrote on Tue, Feb 02, 2021 at 23:17:28 +0100:
> I see that this was the original intended behaviour in the V12zparseopts
> tests, so ignore if I've missed something.

> +++ 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

Haven't tested, but this sounds perfectly reasonable to me.  If anything, I'd
say go a step further and add the first minus sign as well: referring the the
«--x» option as «-x» could be confusing (or even misleading, if there happens
to actually be a -x option).

And the same thing on line 70, I suppose?

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Improve error message from zparseopts -F
  2021-02-03 11:28 ` Daniel Shahaf
@ 2021-02-03 11:36   ` Peter Stephenson
  2021-02-03 15:06   ` Joshua Krusell
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2021-02-03 11:36 UTC (permalink / raw)
  To: Joshua Krusell, zsh-workers

> On 03 February 2021 at 11:28 Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Haven't tested, but this sounds perfectly reasonable to me.  If anything, I'd
> say go a step further and add the first minus sign as well: referring the the
> «--x» option as «-x» could be confusing (or even misleading, if there happens
> to actually be a -x option).
> 
> And the same thing on line 70, I suppose?

As this looked OK, I've just pushed it, so any further changes can arrive as
a separate patch.

Cheers
pws


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Improve error message from zparseopts -F
  2021-02-03 11:28 ` Daniel Shahaf
  2021-02-03 11:36   ` Peter Stephenson
@ 2021-02-03 15:06   ` Joshua Krusell
  1 sibling, 0 replies; 4+ messages in thread
From: Joshua Krusell @ 2021-02-03 15:06 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

On 2021-02-03 at 11:28, Daniel Shahaf wrote:
> Haven't tested, but this sounds perfectly reasonable to me.  If anything, I'd
> say go a step further and add the first minus sign as well: referring the the
> «--x» option as «-x» could be confusing (or even misleading, if there happens
> to actually be a -x option).

Sure, I can send another quick patch. Should also probably change the
missing argument error messages as well to be consistent.

/Joshua


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-03 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 22:17 [PATCH] Improve error message from zparseopts -F Joshua Krusell
2021-02-03 11:28 ` Daniel Shahaf
2021-02-03 11:36   ` Peter Stephenson
2021-02-03 15:06   ` Joshua Krusell

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