Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle unspecified args with ArgParser #121

Closed
DartBot opened this issue Jun 5, 2015 · 7 comments
Closed

Gracefully handle unspecified args with ArgParser #121

DartBot opened this issue Jun 5, 2015 · 7 comments
Labels
P3 A lower priority bug or feature request package:args type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="96" height="96"hspace="10"> Issue by sethladd
Originally opened as dart-lang/sdk#14786


It would be nice to have an option in ArgParser to ignore unspecified args.

Use Case:

Build system specifies its own options.
Build system uses another library that specifies its options.

I want to pass args to both the main build system and the included library:

build.dart --my-option --deploy

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Well, I found this in the API docs:

By default, the parse() method stops as soon as it reaches -- by itself or anything that the parser doesn't recognize as an option, flag, or option value. If arguments still remain, they go into ArgResults.rest.

Which looks like it can help me today.

@DartBot DartBot added type-enhancement A request for a change that isn't a bug P3 A lower priority bug or feature request labels Jun 5, 2015
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


After playing around the -- doesn't help me because the tools generate the command-line, and they don't put their args after --.

So I think I need a "ignore unspecified args" option for ArgParser.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Will you accept a patch for such a feature?


cc @munificent.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


Args has an option now to ignore unspecified arguments, but not unrecognized options. The former lets you have options that appear after non-option arguments. For example:

$ myapp some/file.txt --option

Args can skip over some/file.txt and parse --option. But it doesn't do that for things that look like options (i.e. a leading "-").

I'd be fine with a patch for the latter too, provided it was an opt-in feature. I'm thinking add a "ignoreUnknownOptions" argument to parse().

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Thanks Bob. ignoreUnknownOptions as an opt-IN would work. Good to know you'd accept a patch. :)

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/3276024?v=3" align="left" width="48" height="48"hspace="10"> Comment by anders-sandholm


Removed Library-Args label.
Added Pkg-Args label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Now at #107


Added MovedToGithub label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request package:args type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants