Arguments Package Design / Redesign
This page provides for a collection of thoughts on an extended Arguments package for Tango, and should also serve as a specification for said package. The previous ArgParser? package, while quite useful, was limited in scope. Because of the standardized nature of conventional command line argument parsing, additional features can be provided which would fit in with a standard library.
Concerns
- Creating the need for too complex set-up for simplistic usage. The end product should still support the same or similar usage as the previous ArgParser?, without increasing (hopefully even decreasing) usage complexity.
- ...
Goals
- To provide a package which matches with conventional parsing and usage of command line arguments.
- Providing an argument parsing module that requires minimal use on the part of the user to set up and use in a simplistic fashion. More complex needs can require more complex usage, but the package should still be able to fulfill a minimalist use case without requiring extensive pre-requisite setup.
- Provide a storage area for parsed arguments, and allow the use of D-style array access and 'in' syntax.
- Be able to provide argument validation delegates in a flexible manner.
- Be able to support implicit arguments. (Ala 'myprog file1 file2' instead of 'myprog --files file1 file2').
- Provide access method to command call name.
- (tentative) Provide support for help-text generation.
Solution / Design
- A preliminary reference design is included in bug #748.
References
Issues
- Current reference design has confusing or possibly inconsistent handling of implicit arguments. The discourse on this issue is covered in the discussion for bug #748.
- Reference design has multiple and possibly redundant validation mechanisms. One can apply simple validations using booleans to specify if an argument needs to be specified, or if an argument requires a parameter. However, one can also specify a validation delegate for an argument. Perhaps better to provide simple delegates for the same validations and make use of a common validation adding mechanism.
- Currently there is no way not to make use of Arguments as a storage device for parsed arguments. Perhaps there should be a way to allow the user to store arguments externally, and just make use of the parsing mechanisms? (As the previous ArgParser? was).
Sample Usage
Assume cmdlArgs is the array as passed to main() for all usage examples.
Basic simplistic usage: Given cmdlArgs "myProg -y -z=1 --other:7 --another six"
auto myArgs = new Arguments(cmdlArgs); assert("x" in myArgs); assert("z" in myArgs); assert("other" in myArgs); assert("another" in myArgs); assert(myArgs["y"] is null); assert(myArgs["z"] == "1"); assert(myArgs["other"] == "7"); assert(myArgs["another"] == "six");
Usage with validated arguments:
Usage with aliased arguments:
Usage with implicit arguments:
Usage with pre-determined arguments:
Discussion thread