Comments (4)
<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent
Yeah, this has been in the back of my mind for a while.
What I'd really like is for ArgParser to have support for parsing arguments and not just options. It should be able to pull out mandatory positional arguments too. I've always had that in mind (which is why the package is "args" and not "options"!) I just haven't gotten there.
Supporting this directly would let args do the validation, and would also let it generate a nice usage line for the command.
from args.
<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="48" height="48"hspace="10"> Comment by seaneagan
Positional arguments are fully supported in:
https://pub.dartlang.org/packages/unscripted
Maybe you can port some of it to args
, and then I can use that from unscripted
.
It has an internal Positional
type which shares some properties with Option
, like help
, valueHelp
, allowed
, parser
(e.g. int.parse
), which can be added to a Usage
(unscripted's version of ArgParser) via an addPositional
method:
https://github.com/seaneagan/unscripted/blob/master/lib/src/usage.dart#L50
It also has a Rest
type which inherits from Positional
and defines a "rest parameter" which defines homogeneous trailing positional arguments, and which has a required
property which defines whether or not at least one value is required. It can be assigned to a Usage
via a rest
property since there can only be one of them:
https://github.com/seaneagan/unscripted/blob/master/lib/src/usage.dart#L63
These are all validated upon parsing. They are also used in help text like so:
$ foo.dart --help
Usage:
foo.dart [<options>] <valueHelp1> <valueHelp2> <restValueHelp>...
<valueHelp1> <help1>
<valueHelp2> <help2>
<restValueHelp> <restHelp>
Options:
...
They are also used in unscripted's tab-completion support.
Unscripted does not support optional positionals since dart methods cannot (yet) have both optional named and optional positional arguments, and so supporting optional positionals would mean no "--" options could be added, but presumably args
could support it:
parser
..addPositional(...)
..addPositional(...)
..startOptionalPositionals()
..addPositional(...)
..addPositional(...)
..rest = new Rest(...); // or addRest(...)
from args.
<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="48" height="48"hspace="10"> Comment by seaneagan
One clarification, startOptionalPositionals
could apply to any addRest
call as well, if startOptionalPositionals
was called first, then the rest parameter is optional, otherwise required (at least one value must be provided).
Also, in unscripted I'm considering disallowing adding both positionals and sub-commands to the same Usage (ArgParser in args
case), since that can be ambiguous. I think right now args
assumes anything which matches a sub-command name is the sub-command and not a positional value, but the user might have intended differently. And it would also make the cli invocation hard to read when it includes both positional values and a sub-command name, I don't think I've ever seen it in practice, so shouldn't hurt to disallow it.
from args.
<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="48" height="48"hspace="10"> Comment by seaneagan
Moved to github:
from args.
Related Issues (20)
- Overhaul usage errors to not use exceptions
- Examples for CommandRunner aren't correct on pub page HOT 3
- 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
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.