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

Re: Advanced option parsing across zsh commands



On 26 January 2016 at 19:28, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> } % set -- a -b something -- -c
> } % typeset -A opts
> } % zparseopts -A opts -DE b: c
> } % echo "${(kv)opts}"
> }
> } % # $1, $2, ... $5 are still the same
>
> You can't stack the options of zparseopts itself, i.e, you can't use -DE,
> you have to use -D -E.

Thanks, this works

> zparseopts also doesn't handle "negated options" in the +X format, only
> those introduced with "-".  There's a fairly convoluted issue with making
> "+" work for the associative array case because of the way zparseopts
> gathers up the arguments of each option before assigning to the array.

This sounded like if there would a workaround for +X. I tried the
following: define option "+", which takes argument. Then replace "+X"
with "-+X" in the command line. However:

% unset opts
% typeset -A opts
% set -- a -b something -+X -- -c
% zparseopts -A opts -D -E b: c +:
% echo "${(k)opts}"

% echo "${(v)opts}"
b+X

Weird, isn't it? With also a regular array:

% unset opts
% unset optsa
% typeset -A opts
% typeset -a optsa
% set -- a -b something -+X -- -c
% zparseopts -a optsa -A opts -D -E b: c +:
% echo ${(k)opts}

% echo ${(v)opts}
b+X
% echo $optsa
b - +X

With only regular array it's the same

Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author