[Issue 16604] [std.getopt] defaultGetoptPrinter can't be used if an exception fires
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jan 10 14:07:24 PST 2017
https://issues.dlang.org/show_bug.cgi?id=16604
--- Comment #1 from Eduard Staniloiu <edi33416 at gmail.com> ---
There is a more elegant solution.
You can use the passThrough config directive.
>From the docs:
"Passing unrecognized options through:
If an application needs to do its own processing of whichever arguments getopt
did not understand, it can pass the std.getopt.config.passThrough directive to
getopt.
An unrecognized option such as "--baz" will be found untouched in args after
getopt returns."
So, you could do something like this:
auto helpInformation = getopt(
args,
std.getopt.config.passThrough,
/* Your options here */);
if (helpInformation.helpWanted || (args.length > 1))
{
defaultGetoptPrinter("Some information about the program.",
helpInformation.options);
}
Any mistaken/nonexistent option will be in args, starting with index 1 (at
args[0] you will have the name of your program)
--
More information about the Digitalmars-d-bugs
mailing list