OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library options; | 5 library options; |
6 | 6 |
7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
8 | 8 |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 defaultsTo: false, negatable: false) | 103 defaultsTo: false, negatable: false) |
104 ..addFlag('show-package-warnings', | 104 ..addFlag('show-package-warnings', |
105 help: 'Show warnings from package: imports', | 105 help: 'Show warnings from package: imports', |
106 defaultsTo: false, negatable: false) | 106 defaultsTo: false, negatable: false) |
107 ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports', | 107 ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports', |
108 defaultsTo: false, negatable: false) | 108 defaultsTo: false, negatable: false) |
109 ..addFlag('help', abbr: 'h', help: 'Display this help message', | 109 ..addFlag('help', abbr: 'h', help: 'Display this help message', |
110 defaultsTo: false, negatable: false); | 110 defaultsTo: false, negatable: false); |
111 | 111 |
112 try { | 112 try { |
| 113 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 |
| 114 args = args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(
); |
113 var results = parser.parse(args); | 115 var results = parser.parse(args); |
114 // help requests | 116 // help requests |
115 if (results['help']) { | 117 if (results['help']) { |
116 _showUsage(parser); | 118 _showUsage(parser); |
117 exit(0); | 119 exit(0); |
118 } | 120 } |
119 // batch mode and input files | 121 // batch mode and input files |
120 if (results['batch']) { | 122 if (results['batch']) { |
121 if (results.rest.length != 0) { | 123 if (results.rest.isNotEmpty) { |
122 print('No source files expected in the batch mode.'); | 124 print('No source files expected in the batch mode.'); |
123 _showUsage(parser); | 125 _showUsage(parser); |
124 exit(15); | 126 exit(15); |
125 } | 127 } |
126 } if (results['version']) { | 128 } else if (results['version']) { |
127 print('$_BINARY_NAME version ${_getVersion()}'); | 129 print('$_BINARY_NAME version ${_getVersion()}'); |
128 exit(0); | 130 exit(0); |
129 } else { | 131 } else { |
130 if (results.rest.length == 0) { | 132 if (results.rest.isEmpty) { |
131 _showUsage(parser); | 133 _showUsage(parser); |
132 exit(15); | 134 exit(15); |
133 } | 135 } |
134 } | 136 } |
135 return new CommandLineOptions._fromArgs(results); | 137 return new CommandLineOptions._fromArgs(results); |
136 } on FormatException catch (e) { | 138 } on FormatException catch (e) { |
137 print(e.message); | 139 print(e.message); |
138 _showUsage(parser); | 140 _showUsage(parser); |
139 exit(15); | 141 exit(15); |
140 } | 142 } |
141 | 143 |
142 } | 144 } |
143 | 145 |
144 static _showUsage(parser) { | 146 static _showUsage(parser) { |
145 print('Usage: $_BINARY_NAME [options...] <libraries to analyze...>'); | 147 print('Usage: $_BINARY_NAME [options...] <libraries to analyze...>'); |
146 print(parser.getUsage()); | 148 print(parser.getUsage()); |
147 print(''); | 149 print(''); |
148 print('For more information, see http://www.dartlang.org/tools/analyzer.'); | 150 print('For more information, see http://www.dartlang.org/tools/analyzer.'); |
149 } | 151 } |
150 | 152 |
151 static String _getVersion() { | 153 static String _getVersion() { |
152 try { | 154 try { |
153 Path path = new Path(new Options().script); | 155 Path path = new Path(new Options().script); |
154 Path versionPath = path.directoryPath.append('..').append('version'); | 156 Path versionPath = path.directoryPath.append('..').append('version'); |
155 File versionFile = new File.fromPath(versionPath); | 157 File versionFile = new File.fromPath(versionPath); |
156 | |
157 return versionFile.readAsStringSync().trim(); | 158 return versionFile.readAsStringSync().trim(); |
158 } catch (_) { | 159 } catch (_) { |
159 // This happens when the script is not running in the context of an SDK. | 160 // This happens when the script is not running in the context of an SDK. |
160 return "<unknown>"; | 161 return "<unknown>"; |
161 } | 162 } |
162 } | 163 } |
163 } | 164 } |
164 | 165 |
165 /** | 166 /** |
166 * Commandline argument parser. | 167 * Commandline argument parser. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 253 |
253 _getNextFlagIndex(args, i) { | 254 _getNextFlagIndex(args, i) { |
254 for ( ; i < args.length; ++i) { | 255 for ( ; i < args.length; ++i) { |
255 if (args[i].startsWith('--')) { | 256 if (args[i].startsWith('--')) { |
256 return i; | 257 return i; |
257 } | 258 } |
258 } | 259 } |
259 return i; | 260 return i; |
260 } | 261 } |
261 } | 262 } |
OLD | NEW |