www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17904] New: Enhanced getopt result with passed arguments

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

          Issue ID: 17904
           Summary: Enhanced getopt result with passed arguments
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: andre s-e-a-p.de

It would be nice if the result of getopt would have an attribute
"passedArguments" (or another name) which returns a tuple array of type
(string, bool). First value is the passed argument and the seccond value
indicates whether it was listed in the getopt definition.

Example:

auto helpInformation = getopt(
    args,
    "length",  &length,    // numeric
    "file",    &data,      // string
    "verbose", &verbose,   // flag
    "color", "Information about this color", &color); 


 ./app --file "abc" --anotherOption 15
helpInformation.passedArguments would now contain an array of 2 elements [tuple("file", true), tuple("anotherOption", false)] Use case: If would like to enable following console command ./app set-config --optional-value1 (true|false) --optional-value2 (true-false) - Either optional-value1 or optinal-value2 or both must be given. Otherwise error - Either true or false have to be specified. Otherwise error I already found a solution but the passedArguments attribute would make the coding much more readable. --
Oct 16 2017