[Issue 20948] New: std.getopt: Support std.getop.config.positional
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 18 12:08:40 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20948
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 at puremagic.com
Reporter: andre at 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
https://docs.python.org/3/library/argparse.html
In D, positional arguments could also be supported using a new config value
`positional`:
string foo;
string bar;
getopt(args,
std.getopt.config.positional,
"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.
--
More information about the Digitalmars-d-bugs
mailing list