OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * The main entrypoint for the pub command line application. | 6 * The main entrypoint for the pub command line application. |
7 */ | 7 */ |
8 #library('pub'); | 8 #library('pub'); |
9 | 9 |
10 #import('../../lib/args/args.dart'); | 10 #import('../../lib/args/args.dart'); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 parser.addFlag('version', negatable: false, | 51 parser.addFlag('version', negatable: false, |
52 help: 'Prints the version of Pub'); | 52 help: 'Prints the version of Pub'); |
53 parser.addFlag('trace', help: 'Prints a stack trace when an error occurs'); | 53 parser.addFlag('trace', help: 'Prints a stack trace when an error occurs'); |
54 return parser; | 54 return parser; |
55 } | 55 } |
56 | 56 |
57 main() { | 57 main() { |
58 var globalOptions; | 58 var globalOptions; |
59 try { | 59 try { |
60 globalOptions = pubArgParser.parse(new Options().arguments); | 60 globalOptions = pubArgParser.parse(new Options().arguments); |
61 } catch (ArgFormatException e) { | 61 } catch (FormatException e) { |
62 printUsage(description: e.message); | 62 printUsage(description: e.message); |
63 return; | 63 return; |
64 } | 64 } |
65 | 65 |
66 if (globalOptions['version']) { | 66 if (globalOptions['version']) { |
67 printVersion(); | 67 printVersion(); |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 if (globalOptions['help'] || globalOptions.rest.isEmpty()) { | 71 if (globalOptions['help'] || globalOptions.rest.isEmpty()) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 */ | 162 */ |
163 ArgParser get commandParser() => new ArgParser(); | 163 ArgParser get commandParser() => new ArgParser(); |
164 | 164 |
165 void run(SystemCache cache_, ArgResults globalOptions_, | 165 void run(SystemCache cache_, ArgResults globalOptions_, |
166 List<String> commandArgs) { | 166 List<String> commandArgs) { |
167 cache = cache_; | 167 cache = cache_; |
168 globalOptions = globalOptions_; | 168 globalOptions = globalOptions_; |
169 | 169 |
170 try { | 170 try { |
171 commandOptions = commandParser.parse(commandArgs); | 171 commandOptions = commandParser.parse(commandArgs); |
172 } catch (ArgFormatException e) { | 172 } catch (FormatException e) { |
173 this.printUsage(description: e.message); | 173 this.printUsage(description: e.message); |
174 return; | 174 return; |
175 } | 175 } |
176 | 176 |
177 handleError(error, trace) { | 177 handleError(error, trace) { |
178 // This is basically the top-level exception handler so that we don't | 178 // This is basically the top-level exception handler so that we don't |
179 // spew a stack trace on our users. | 179 // spew a stack trace on our users. |
180 // TODO(rnystrom): Add --trace flag so stack traces can be enabled for | 180 // TODO(rnystrom): Add --trace flag so stack traces can be enabled for |
181 // debugging. | 181 // debugging. |
182 var message = error.toString(); | 182 var message = error.toString(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 print(''); | 227 print(''); |
228 print('Usage: $usage'); | 228 print('Usage: $usage'); |
229 | 229 |
230 var commandUsage = commandParser.getUsage(); | 230 var commandUsage = commandParser.getUsage(); |
231 if (!commandUsage.isEmpty()) { | 231 if (!commandUsage.isEmpty()) { |
232 print(''); | 232 print(''); |
233 print(commandUsage); | 233 print(commandUsage); |
234 } | 234 } |
235 } | 235 } |
236 } | 236 } |
OLD | NEW |