Comments (5)
I'm skeptical of adding such a complex and detailed validation API for positional arguments. In my experience, the handling of positional arguments is very idiosyncratic; either it's something very simple like "this takes two or three arguments" or it's something very complicated that isn't worth the hassle of trying to write an API to express. I'd still prefer the much simpler minPositional
/maxPositional
API I proposed originally in issue 20042.
from args.
I would personally think I would enjoy more structure around the positional args. I find myself using options
just so it is better self-documenting, better structured in the code and with more strict checks.
from args.
The above proposed API is not complex, addPositional(...)
/addRest(...)
are pretty much exactly like the existing addFlag(...)
/addOption(...)
, and startOptionalPositionals()
doesn't even take any arguments. Yet it covers any cases I'm aware of how positional arguments are passed to commands.
@nex3 can you give an example of a command-line interface which this simple API does not handle?
from args.
The above proposed API is not complex,
addPositional(...)
/addRest(...)
are pretty much exactly like the existingaddFlag(...)
/addOption(...)
, andstartOptionalPositionals()
doesn't even take any arguments. Yet it covers any cases I'm aware of how positional arguments are passed to commands.
Clearly I disagree.
@nex3 can you give an example of a command-line interface which this simple API does not handle?
It doesn't handle things like "zero or two parameters" or "allow this flag only with a positional argument" or "the first positional should be named foo
unless there's a second in which case it should be named bar
". All of these require extra munging after the arguments have been parsed.
from args.
It doesn't handle things like "zero or two parameters"
Do you have a real world example? Surely there is a better design.
or "allow this flag only with a positional argument"
That's not specific to positional arguments, it's just a special case of "allow this argument only with this other argument".
or "the first positional should be named foo unless there's a second in which case it should be named bar".
So some_command foo
or some_command bar baz
? foo
and bar
are sub-commands then, not positional arguments.
All of these require extra munging after the arguments have been parsed.
Again, this is not specific to positional arguments, or even to command-line interfaces. It's just as common with (sets of) named arguments, and with programming language interfaces to have to do "precondition checks" after the arguments have passed the built-in standardized signature checks.
from args.
Related Issues (20)
- Statically typed argument parser (possibly with code generator)? HOT 3
- Add a CommandRunner example HOT 2
- Why is `CommandRunner._usageWithoutDescription` private?
- Promote Command.argResults to be non-nullable HOT 1
- Make allowed options case insensitive
- How to add default command?
- Provide the function to print strings in nice columns
- Standards used in docopt. HOT 2
- [Feature request] Show command alias in usage HOT 3
- Command CommandRunner Platform.executableArguments HOT 3
- use of 'mandatory' options breaks handling of the help flag
- Feature request: parse complete command string to List<String> args HOT 3
- Analogue of '::' GNU getopt extension? HOT 1
- `--` needs to be escaped on Windows HOT 2
- Usage should be able to show additional info for trailing options (rest)
- Setting the mandatory parameter of the addOption function to true has no effect. HOT 1
- `takesArguments` should change the usage text
- Incorrect message in `dart_site --help` HOT 1
- remove nullability from `ArgParser.addFlag({bool? defaultsTo = false})`
- default branch renamed from `master` to `main`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from args.