www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16604] New: [std.getopt] defaultGetoptPrinter can't be used

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

          Issue ID: 16604
           Summary: [std.getopt] defaultGetoptPrinter can't be used if an
                    exception fires
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/phobos/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kevin brogan.ca

If an exception is thrown by getopt, the GetoptResults.options array is never
returned. If it isn't returned, then I can't use the defaultGetoptPrinter
function. This makes it impossible to call defaultGetoptPrinter in the event
that a program's user ever makes a mistake.

The GetoptResults.options array is static regardless of what options are passed
to the arguments of the program. It should always be built before any
exceptions fire.

The only way around this is to have an exception show a generic "you made a
mistake calling the program, call 'program --help' to see usage", or to call
getopt with an empty args string and no required parameters to build a second
options array first. Both are klunky.

--
Oct 08 2016