Bug 14921 – getopt throws preventing printing of options

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-14T20:29:00Z
Last change time
2016-01-31T14:11:59Z
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2015-08-14T20:29:33Z
std.getopt.getopt can throw. What do you print in this case, since the mechanism used to print the help is embedded in the GetOptResult that is returned? I think there should be a configuration option to embed in the GetOptResult the error message instead of throwing it. At the moment, I have an ugly workaround: void main(string[] args) { void callGetOpt(ref string[] a) { getoptresult = getopt(a, ...); } try { callGetOpt(args); if(getoptresult.helpRequested) usage(getoptresult); } catch(Exception ex) { callGetOpt(null); // generate the help anyway usage(getoptresult); // print usage } ... }
Comment #1 by schveiguy — 2015-08-14T20:40:08Z
Note, the workaround only works if you *don't* have required options.
Comment #2 by john.loughran.colvin — 2016-01-31T14:11:59Z
*** This issue has been marked as a duplicate of issue 14525 ***