www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14921] New: getopt throws preventing printing of options

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

          Issue ID: 14921
           Summary: getopt throws preventing printing of options
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: schveiguy yahoo.com

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
   }
   ...
}

--
Aug 14 2015