Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Issue 11824044: Ignore unhandled arguments instead of stopping parsing. (Closed)

Created:
7 years, 11 months ago by Bob Nystrom
Modified:
6 years, 10 months ago
Reviewers:
nweiz, ahe, Emily Fortuna
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Ignore unhandled arguments instead of stopping parsing. BUG=5262

Patch Set 1 #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+32 lines, -33 lines) Patch
M pkg/args/lib/args.dart View 6 chunks +12 lines, -12 lines 0 comments Download
M pkg/args/test/parse_test.dart View 6 chunks +20 lines, -21 lines 3 comments Download

Messages

Total messages: 9 (0 generated)
Bob Nystrom
Peter, I think this gets you a bit closer to being able to use this ...
7 years, 11 months ago (2013-01-09 22:05:36 UTC) #1
Emily Fortuna
lgtm
7 years, 11 months ago (2013-01-09 23:29:18 UTC) #2
Bob Nystrom
On 2013/01/09 23:29:18, Emily Fortuna wrote: > lgtm Nathan pointed out to me that this ...
7 years, 11 months ago (2013-01-10 00:55:43 UTC) #3
ahe
I'm looking forward to getting rid of the current arg parsing hack in dart2js. I ...
7 years, 11 months ago (2013-01-10 07:39:26 UTC) #4
Bob Nystrom
On 2013/01/10 07:39:26, ahe wrote: > I'm looking forward to getting rid of the current ...
7 years, 11 months ago (2013-01-10 17:29:47 UTC) #5
ahe
Test LGTM, didn't look at implementation. https://codereview.chromium.org/11824044/diff/1/pkg/args/test/parse_test.dart File pkg/args/test/parse_test.dart (right): https://codereview.chromium.org/11824044/diff/1/pkg/args/test/parse_test.dart#newcode397 pkg/args/test/parse_test.dart:397: expect(results.rest, orderedEquals(['a', 'b', ...
7 years, 11 months ago (2013-01-10 19:51:40 UTC) #6
Bob Nystrom
https://codereview.chromium.org/11824044/diff/1/pkg/args/test/parse_test.dart File pkg/args/test/parse_test.dart (right): https://codereview.chromium.org/11824044/diff/1/pkg/args/test/parse_test.dart#newcode397 pkg/args/test/parse_test.dart:397: expect(results.rest, orderedEquals(['a', 'b', 'd'])); On 2013/01/10 19:51:40, ahe wrote: ...
7 years, 11 months ago (2013-01-10 23:16:40 UTC) #7
ahe
Tests still LGTM. Have another feature request, but it isn't a show stopper for dart2js. ...
7 years, 11 months ago (2013-01-11 05:37:28 UTC) #8
Bob Nystrom
7 years, 11 months ago (2013-01-11 17:03:21 UTC) #9
On 2013/01/11 05:37:28, ahe wrote:
> Tests still LGTM.
> 
> Have another feature request, but it isn't a show stopper for dart2js.
> 
> https://codereview.chromium.org/11824044/diff/1/pkg/args/test/parse_test.dart
> File pkg/args/test/parse_test.dart (right):
> 
>
https://codereview.chromium.org/11824044/diff/1/pkg/args/test/parse_test.dart...
> pkg/args/test/parse_test.dart:397: expect(results.rest, orderedEquals(['a',
'b',
> 'd']));
> On 2013/01/10 23:16:40, Bob Nystrom wrote:
> > On 2013/01/10 19:51:40, ahe wrote:
> > > Could you add a test that you reject unknown arguments that look like
> options?
> > 
> > The tests on 252 and 329 should cover that, I think.
> 
> Yes. I guess I was skipping exceptions when I scanned for this.
> 
> Would it be possible to provide an onError callback so you can handle these
> situations without throwing an exception?

I'm not generally a fan of errbacks for error-handling in synchronous code, but
I would like a nice answer for your use case.

> 
> I have two use cases in mind:
> 
> * You wrap another application, but want to add a few additional arguments. So
> the facade will pass everything through that it doesn't understand.

This patch makes it so that unhandled arguments pass through, but unhandled
arguments that look like options don't. I was thinking of adding an optional
parameter to parse(): parse(ignoreUnknownOptions: true);

If you pass that, then unhandled options will be treated like unhandled
arguments and end up in the ArgResults.rest. Would that work for this?

> 
> * You can easily provide a "showUsageAndExit" method.

Yeah, I'd definely like a method that does all of the basic stuff in one step:

1. Parse the args directly from new Options().arguments.
2. If "--help" was passed, show the help and exit.
3. If the parse failed, show the help and exit.
4. Otherwise, return the results.

The main sticking points are:

1. Pub wouldn't actually use this functionality until command support is in
args. It needs to have its own usage text to show those right now.

2. Currently, args isn't actually coupled to dart:io. I'd be surprised if it was
ever used in an environment where dart:io isn't available, but I tried to avoid
that coupling, which is why you always have to pass in the command-line
arguments right now.

I'd be OK with giving up #2, but I'd like to fix #1 first. I find I do better
API design if I have a real-world app to dogfood it against.

If you'd like, can you file bugs for these? Otherwise, I will definitely forget.
Thanks!

Powered by Google App Engine
This is Rietveld 408576698