getopt: How does arraySep work?

Steven Schveighoffer schveiguy at gmail.com
Tue Jul 14 13:40:44 UTC 2020


On 7/14/20 7:12 AM, Andre Pany wrote:
> Hi,
> 
> by reading the documentation of std.getopt I would assume, this is a 
> valid call
> 
> dmd -run sample.d --modelicalibs a b
> 
> ``` d
> import std;
> 
> void main(string[] args)
> {
>      string[] modelicaLibs;
>      getopt(args, "modelicalibs", &modelicaLibs);
>      assert(modelicaLibs == ["a", "b"]);
> }
> ```
> 
> but it fails, as array modelicaLIbs only contains ["a"].
> 
> The std.getopt : arraySep documentation hints that it should work:
>> The string used to separate the elements of an array or associative 
>> array (default is "" which means the elements are separated by 
>> whitespace).
> 
> Is my understanding wrong, or is this a bug?

The whitespace separator doesn't get to your program. args is:

["sample", "--modelicalibs", "a", "b"]

There is no separator in the parameter to --modelicalibs, it's just "a".

What you need to do is:

dmd -run sample.d --modilicalibs "a b"

-Steve


More information about the Digitalmars-d-learn mailing list