mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
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:
parent
01ede06509
commit
07716c5523
2 changed files with 3 additions and 27 deletions
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue