[Issue 16604] [std.getopt] defaultGetoptPrinter can't be used if an exception fires

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 11 04:00:13 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=16604

Witold Baryluk <witold.baryluk+d at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |witold.baryluk+d at gmail.com

--- Comment #2 from Witold Baryluk <witold.baryluk+d at gmail.com> ---
Yeah, I did find the exception throwing a bit problematic, and after some time
of scratching, used similar trick to what Eduard proposed here.

But the fact that getopt is a function the immediately operates on the args,
and doesn't provide introspection or compostability is a problem.

I think a Python argparse has a bit more interesting design, not because of it
OOP-ness, but because it can have sub-parsers, you can compose them compose
them easily, i.e. if you have multiple libraries that can be tweaked by some
program flags, it is essentially impossible to use getopt. You can grab the
unprocessed args, but then there is no easy way to forward it to other
consumers implicitly really.

I grow a lot with Google flags ( https://github.com/gflags/gflags ) and golang
flags (https://golang.org/pkg/flag/) when I did work at Google, and in fact I
like them a lot. Similar solutions exist for Java.


If there is a way to do this things easily with getopt, I think documentation
should be updated to show how to do it.

--


More information about the Digitalmars-d-bugs mailing list