String argument with optional value in std.getopt
Hassan
azi.hassan at live.fr
Sat Aug 8 23:58:01 UTC 2020
Hello
I'm trying to get getopt to recognize an argument that may or may
not take a value. Here's an example :
./hashtrack --list
./hashtrack --list filter
The problem is that if I point list to a string variable, the
first call fails with "Missing value for argument --list".
I tried having it point to a callback with an optional second
parameter :
void cb(string option, string value = "")
{
writeln("--list");
option.writeln();
value.writeln();
}
But I get the same error. I also tried having two callbacks with
the same name. The first one takes a single argument, and the
second one accepts two :
void cb(string option)
{
writeln("--list");
option.writeln();
}
void cb(string option, string value)
{
writeln("--list");
option.writeln();
value.writeln();
}
But it only calls the first one. I'm using DMD64 D Compiler
v2.090.0. Any pointers ?
More information about the Digitalmars-d-learn
mailing list