std.getopt: Unexpected behavior when using incremental options

Ky-Anh Huynh saigon at example.net
Sun Jul 29 12:00:03 UTC 2018


On Sunday, 29 July 2018 at 10:57:06 UTC, Cym13 wrote:
> On Sunday, 29 July 2018 at 09:28:41 UTC, Ky-Anh Huynh wrote:
>> Hi,
>>
>> I am using std.getopt and expect to parse an incremental 
>> option with different names: --long, --longer, -l. The sample 
>> code is here
>>
>> [...]
>
> I think -long is actually taken as -l -o -n -g here. Since you 
> didn't define -o, -n and -g it prints a usage error.

I think that I've got that. There isn't any actual definition of 
short/long option names. That means if I provide

[code]
     "l|long|longer+", &s_long
[/code]

getopt will define 6 variants: -l, --l, -long, --long, -longer, 
--longer, and here `-long`, `-l` and `-longer` are both short:) 
`Short` isn't related to the length of the option name. It's 
short because there is only one dash (-). This way using "short" 
is quite confusing.

Regarding the output of the default help message, I should put 
`l` at the first position, as in `l|long|longer`. This is 
slightly different from examples in the official documentation 
(https://dlang.org/phobos/std_getopt.html) where you are expected 
to see `long|longer|l+` instead.


More information about the Digitalmars-d mailing list