1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-04 14:46:20 +02:00

47905: Add leading '-' to zparseopts option parsing errors

This commit is contained in:
Joshua Krusell 2021-02-03 16:46:59 +01:00 committed by Oliver Kiddle
parent 2cf6032a30
commit 3d6e5b6231
3 changed files with 15 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2021-02-13 Oliver Kiddle <opk@zsh.org>
* 47905: Joshua Krusell: Src/Modules/zutil.c,
Test/V12zparseopts.ztst: Add leading '-' to zparseopts option
parsing errors
2021-02-11 Bart Schaefer <schaefer@zsh.org> 2021-02-11 Bart Schaefer <schaefer@zsh.org>
* unposted: NEWS, README: mention the effects of 47997. * unposted: NEWS, README: mention the effects of 47997.

View File

@ -1874,9 +1874,9 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
if (!(d = sopts[STOUC(*o)])) { if (!(d = sopts[STOUC(*o)])) {
if (fail) { if (fail) {
if (*o != '-') if (*o != '-')
zwarnnam(nam, "bad option: %c", *o); zwarnnam(nam, "bad option: -%c", *o);
else else
zwarnnam(nam, "bad option: %s", o); zwarnnam(nam, "bad option: -%s", o);
return 1; return 1;
} }
o = NULL; o = NULL;
@ -1889,7 +1889,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
} else if (!(d->flags & ZOF_OPT) || } else if (!(d->flags & ZOF_OPT) ||
(pp[1] && pp[1][0] != '-')) { (pp[1] && pp[1][0] != '-')) {
if (!pp[1]) { if (!pp[1]) {
zwarnnam(nam, "missing argument for option: %s", zwarnnam(nam, "missing argument for option: -%s",
d->name); d->name);
return 1; return 1;
} }
@ -1916,7 +1916,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
else if (!(d->flags & ZOF_OPT) || else if (!(d->flags & ZOF_OPT) ||
(pp[1] && pp[1][0] != '-')) { (pp[1] && pp[1][0] != '-')) {
if (!pp[1]) { if (!pp[1]) {
zwarnnam(nam, "missing argument for option: %s", zwarnnam(nam, "missing argument for option: -%s",
d->name); d->name);
return 1; return 1;
} }

View File

@ -65,11 +65,11 @@
} $=1 } $=1
done done
0:zparseopts -F 0:zparseopts -F
?(anon):zparseopts:2: bad option: x
>ret: 1, optv: , argv: -a -x -z
?(anon):zparseopts:2: bad option: x
>ret: 1, optv: , argv: -ax -z
?(anon):zparseopts:2: bad option: -x ?(anon):zparseopts:2: bad option: -x
>ret: 1, optv: , argv: -a -x -z
?(anon):zparseopts:2: bad option: -x
>ret: 1, optv: , argv: -ax -z
?(anon):zparseopts:2: bad option: --x
>ret: 1, optv: , argv: -a --x -z >ret: 1, optv: , argv: -a --x -z
for 1 in '-a 1 2 3' '1 2 3'; do for 1 in '-a 1 2 3' '1 2 3'; do
@ -168,5 +168,5 @@
print -r - ret: $?, optv: $optv, argv: $argv print -r - ret: $?, optv: $optv, argv: $argv
} -ab1 -c } -ab1 -c
0:missing optarg 0:missing optarg
?(anon):zparseopts:2: missing argument for option: c ?(anon):zparseopts:2: missing argument for option: -c
>ret: 1, optv: , argv: -ab1 -c >ret: 1, optv: , argv: -ab1 -c