Subject: Re: Advanced option parsing across zsh commands
From: Sebastian Gniazdowski <[email-masked]>
To: Bart Schaefer <[email-masked]>
Cc: Zsh hackers list <[email-masked]>
Date: Tue, 26 Jan 2016 19:59:40 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On 26 January 2016 at 19:28, Bart Schaefer <[email-masked]> 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