Bug 20948 – std.getopt: Support std.getop.config.positional

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-18T12:08:40Z
Last change time
2024-12-01T16:37:02Z
Assigned to
No Owner
Creator
Andre
Moved to GitHub: phobos#9798 →

Comments

Comment #0 by andre — 2020-06-18T12:08:40Z
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.
Comment #1 by robert.schadek — 2024-12-01T16:37:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9798 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB