www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20948] New: std.getopt: Support std.getop.config.positional


          Issue ID: 20948
           Summary: std.getopt: Support std.getop.config.positional
           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

std.getopt supports optional arguments (starting with --) but does not support
mandatory arguments (positional arguments). 

Please see the very first example how this is solved in python library argparse

In D, positional arguments could also be supported using a new config value

string foo;
string bar;

    "foo", &foo, // positional argument
    "bar", &bar  // non positional argument

You can call the application with
 myapp ABC --bar DEF
Value ABC would be assigned to string variable `foo`. The string "foo" serves for documentation purposes while calling the getopt help. Supporting positional arguments in getopt would be a lot more convenient and would provide a better user experience (getopt help) instead of having custom parsing/validation logic implemented in each application different. --
Jun 18 2020