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

Unified Diff: lib/compiler/implementation/dart2js.dart

Issue 10377023: Using arg parsing lib for dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update with review feedback. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/args/args.dart ('k') | tests/lib/args/args_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart2js.dart
diff --git a/lib/compiler/implementation/dart2js.dart b/lib/compiler/implementation/dart2js.dart
index 7b7fa6bc6ff4f8c943a19202fe908146307882fd..9214eee9236b66b6bdb949b67eab68e4c7fbb664 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');
@@ -16,47 +17,54 @@
final String LIBRARY_ROOT = '../../../..';
-void compile(List<String> argv) {
+ArgResults parseCommandLine(List<String> argv) {
+ // Set up and parse the command line arguments.
+ ArgParser parser = new ArgParser(usage: 'dart2js [options...] <dart file>');
+ 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',
+ 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');
+
+ return parser.process(argv);
+}
+
+void compile(ArgResults args) {
+ colors.enabled = args['colors'];
+ bool throwOnError = args['throw-on-error'];
+ bool showWarnings = !args['suppress-warnings'];
+ bool verbose = args['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 (args['library-root'] != null) {
+ String path = nativeToUriPath(args['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 ('--enable-checked-mode' == argument) {
- options.add(argument);
- } else if (argument.startsWith('-')) {
- fail('Unknown option $argument.');
- } else {
- arguments.add(nativeToUriPath(argument));
- }
+ Uri out = cwd.resolve(args['out']);
+
+ List<String> options = new List<String>();
+ if (args['allow-mock-compilation']) {
+ options.add('--allow-mock-compilation');
}
+
+ List<String> arguments = args.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.');
@@ -145,7 +153,8 @@ void compilerMain(Options options) {
var root = uriPathToNative("/$LIBRARY_ROOT");
List<String> argv = ['--library-root=${options.script}$root'];
argv.addAll(options.arguments);
- compile(argv);
+ ArgResults results = parseCommandLine(argv);
+ compile(results);
}
void main() {
« no previous file with comments | « lib/args/args.dart ('k') | tests/lib/args/args_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698