Chromium Code Reviews| Index: lib/compiler/implementation/dart2js.dart |
| diff --git a/lib/compiler/implementation/dart2js.dart b/lib/compiler/implementation/dart2js.dart |
| index 87b60e08b6271bce0fd1ca1fd20452c7bd7d3523..26124dc4fac7ed16077e8534bf31cc61ce5ab9e4 100644 |
| --- a/lib/compiler/implementation/dart2js.dart |
| +++ b/lib/compiler/implementation/dart2js.dart |
| @@ -8,6 +8,7 @@ |
| #import('dart:uri'); |
| #import('dart:utf'); |
| +#import('../../args/args.dart'); |
| #import('../compiler.dart', prefix: 'api'); |
| #import('colors.dart', prefix: 'colors'); |
| #import('source_file.dart'); |
| @@ -17,44 +18,51 @@ |
| final String LIBRARY_ROOT = '../../../..'; |
| void compile(List<String> argv) { |
| + // Set up and parse the command line arguments. |
|
ahe
2012/05/07 12:49:06
Could you move the parser construction into a sepa
Bob Nystrom
2012/05/07 18:22:05
Done.
|
| + ArgParser parser = new ArgParser(usage: 'dart2js [options...] <entrypoint>'); |
|
kasperl
2012/05/07 11:49:35
<entrypoint> -> <input>?
ahe
2012/05/07 12:49:06
How about <dart file> or <file>?
Bob Nystrom
2012/05/07 18:22:05
<input entrypoint dart file>? ;)
Changed to <dart
|
| + parser.addFlag('throw-on-error', |
| + help: 'Throw an exception if a fatal error occurs'); |
| + parser.addFlag('suppress-warnings', |
| + help: 'Display static warnings'); |
| + parser.addFlag('verbose', abbr: 'v', |
|
kasperl
2012/05/07 11:49:35
I'd prefer it if abbr wasn't abbreviated (feedback
Bob Nystrom
2012/05/07 18:22:05
I'm not crazy about it either. I think I'll change
|
| + help: 'Display verbose output'); |
| + parser.addFlag('allow-mock-compilation'); |
| + parser.addFlag('colors', defaultsTo: true, |
| + help: 'Use color when displaying output'); |
| + parser.addOption('library-root', |
| + help: 'Path to core lib directory'); |
| + parser.addOption('out', abbr: 'o', |
| + help: 'Output JavaScript file to create', |
| + defaultsTo: 'out.js'); |
|
kasperl
2012/05/07 11:49:35
Indentation.
Bob Nystrom
2012/05/07 18:22:05
Done.
|
| + |
| + ArgResults results = parser.process(argv); |
| + |
| + colors.enabled = results['colors']; |
| + bool throwOnError = results['throw-on-error']; |
| + bool showWarnings = !results['suppress-warnings']; |
| + bool verbose = results['verbose']; |
| + |
| Uri cwd = getCurrentDirectory(); |
| - bool throwOnError = false; |
| - bool showWarnings = true; |
| - bool verbose = false; |
| Uri libraryRoot = cwd; |
| - Uri out = cwd.resolve('out.js'); |
| - List<String> options = new List<String>(); |
| + if (results['library-root'] != null) { |
| + String path = nativeToUriPath(results['library-root']); |
| + if (!path.endsWith("/")) path = "$path/"; |
| + libraryRoot = cwd.resolve(path); |
| + } |
| - List<String> arguments = <String>[]; |
| - for (String argument in argv) { |
| - if ('--throw-on-error' == argument) { |
| - throwOnError = true; |
| - } else if ('--suppress-warnings' == argument) { |
| - showWarnings = false; |
| - } else if ('--verbose' == argument) { |
| - verbose = true; |
| - } else if (argument.startsWith('--library-root=')) { |
| - String path = |
| - nativeToUriPath(argument.substring(argument.indexOf('=') + 1)); |
| - if (!path.endsWith("/")) path = "$path/"; |
| - libraryRoot = cwd.resolve(path); |
| - } else if (argument.startsWith('--out=')) { |
| - String path = |
| - nativeToUriPath(argument.substring(argument.indexOf('=') + 1)); |
| - out = cwd.resolve(path); |
| - } else if ('--allow-mock-compilation' == argument) { |
| - options.add(argument); |
| - } else if ('--no-colors' == argument) { |
| - colors.enabled = false; |
| - } else if (argument.startsWith('-')) { |
| - fail('Unknown option $argument.'); |
| - } else { |
| - arguments.add(nativeToUriPath(argument)); |
| - } |
| + Uri out = cwd.resolve(results['out']); |
| + |
| + List<String> options = new List<String>(); |
| + if (results['allow-mock-compilation']) { |
| + options.add('--allow-mock-compilation'); |
| } |
| + |
| + List<String> arguments = results.rest.map(nativeToUriPath); |
| + |
| if (arguments.isEmpty()) { |
| fail('No file to compile.'); |
| } |
| + |
| if (arguments.length > 1) { |
| var extra = arguments.getRange(1, arguments.length - 1); |
| fail('Extra arguments: $extra.'); |