Options parsing cleanup.

Review URL: https://codereview.chromium.org//12049028

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17669 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
pquitslund@google.com 2013-01-25 23:25:29 +00:00
parent 01ede06509
commit 07716c5523
2 changed files with 3 additions and 27 deletions

View file

@ -36,7 +36,7 @@ class AnalysisResult {
*/
Future<AnalysisResult> run(List<String> args) {
var options = CommandLineOptions.parse(args);
var options = new CommandLineOptions.parse(args);
if (options == null) {
return new Future.immediate(new AnalysisResult.forFailure());
}

View file

@ -114,7 +114,6 @@ class _CommandLineParser {
: _knownFlags = <String>[],
_parser = new ArgParser();
/**
* Defines a flag.
*
@ -140,7 +139,6 @@ class _CommandLineParser {
allowMultiple: allowMultiple);
}
/**
* Generates a string displaying usage information for the defined options.
*
@ -164,31 +162,9 @@ class _CommandLineParser {
}
// Filter all unrecognized flags and options.
var filtered = <String>[];
for (var i=0; i < args.length; ++i) {
var arg = args[i];
if (arg.startsWith('--') && arg.length > 2) {
if (!_knownFlags.contains(arg.substring(2))) {
//"eat" params by advancing to the next flag/option
i = _getNextFlagIndex(args, i);
} else {
filtered.add(arg);
}
} else {
filtered.add(arg);
}
}
return args.where((arg) => !arg.startsWith('--') ||
_knownFlags.contains(arg.substring(2)));
return filtered;
}
_getNextFlagIndex(args, i) {
for ( ; i < args.length; ++i) {
if (args[i].startsWith('--')) {
return i;
}
}
return i;
}
}