getopt: How does arraySep work?

Steven Schveighoffer schveiguy at gmail.com
Tue Jul 14 14:05:59 UTC 2020


On 7/14/20 9:51 AM, Anonymouse wrote:
> On Tuesday, 14 July 2020 at 11:12:06 UTC, Andre Pany wrote:
>> [...]
> 
> Steven Schveighoffer already answered while I was composing this, so 
> discarding top half.
> 
> As far as I can tell the default arraySep of "" splitting the argument 
> by whitespace is simply not the case.
> 
>> https://github.com/dlang/phobos/blob/master/std/getopt.d#L923
> 
>      // ...
>      else static if (isArray!(typeof(*receiver)))
>      {
>          // array receiver
>          import std.range : ElementEncodingType;
>          alias E = ElementEncodingType!(typeof(*receiver));
> 
>          if (arraySep == "")
>          {
>              *receiver ~= to!E(val);
>          }
>          else
>          {
>              foreach (elem; val.splitter(arraySep).map!(a => to!E(a))())
>                  *receiver ~= elem;
>          }
>      }
> 
> So you will probably want an arraySep of " " if you want --modelicalibs 
> "a b".

Hm... that looks like it IS actually expecting to do what Andre wants. 
It's adding each successive parameter.

If that doesn't work, then there's something wrong with the logic that 
decides whether a parameter is part of the previous argument or not.

Please file a bug.

-Steve


More information about the Digitalmars-d-learn mailing list