| 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('../../pkg/args/args.dart'); | 10 #import('../../pkg/args/args.dart'); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 parser.addFlag('version', negatable: false, | 52 parser.addFlag('version', negatable: false, |
| 53 help: 'Prints the version of Pub'); | 53 help: 'Prints the version of Pub'); |
| 54 parser.addFlag('trace', help: 'Prints a stack trace when an error occurs'); | 54 parser.addFlag('trace', help: 'Prints a stack trace when an error occurs'); |
| 55 return parser; | 55 return parser; |
| 56 } | 56 } |
| 57 | 57 |
| 58 main() { | 58 main() { |
| 59 var globalOptions; | 59 var globalOptions; |
| 60 try { | 60 try { |
| 61 globalOptions = pubArgParser.parse(new Options().arguments); | 61 globalOptions = pubArgParser.parse(new Options().arguments); |
| 62 } catch (FormatException e) { | 62 } on FormatException catch (e) { |
| 63 printUsage(description: e.message); | 63 printUsage(description: e.message); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (globalOptions['version']) { | 67 if (globalOptions['version']) { |
| 68 printVersion(); | 68 printVersion(); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (globalOptions['help'] || globalOptions.rest.isEmpty()) { | 72 if (globalOptions['help'] || globalOptions.rest.isEmpty()) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 */ | 163 */ |
| 164 ArgParser get commandParser => new ArgParser(); | 164 ArgParser get commandParser => new ArgParser(); |
| 165 | 165 |
| 166 void run(SystemCache cache_, ArgResults globalOptions_, | 166 void run(SystemCache cache_, ArgResults globalOptions_, |
| 167 List<String> commandArgs) { | 167 List<String> commandArgs) { |
| 168 cache = cache_; | 168 cache = cache_; |
| 169 globalOptions = globalOptions_; | 169 globalOptions = globalOptions_; |
| 170 | 170 |
| 171 try { | 171 try { |
| 172 commandOptions = commandParser.parse(commandArgs); | 172 commandOptions = commandParser.parse(commandArgs); |
| 173 } catch (FormatException e) { | 173 } on FormatException catch (e) { |
| 174 this.printUsage(description: e.message); | 174 this.printUsage(description: e.message); |
| 175 return; | 175 return; |
| 176 } | 176 } |
| 177 | 177 |
| 178 handleError(error, trace) { | 178 handleError(error, trace) { |
| 179 // This is basically the top-level exception handler so that we don't | 179 // This is basically the top-level exception handler so that we don't |
| 180 // spew a stack trace on our users. | 180 // spew a stack trace on our users. |
| 181 // TODO(rnystrom): Add --trace flag so stack traces can be enabled for | 181 // TODO(rnystrom): Add --trace flag so stack traces can be enabled for |
| 182 // debugging. | 182 // debugging. |
| 183 var message = error.toString(); | 183 var message = error.toString(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 199 // subdirectories until we hit one that looks package-like. For now, just | 199 // subdirectories until we hit one that looks package-like. For now, just |
| 200 // assume the cwd is it. | 200 // assume the cwd is it. |
| 201 var future = Package.load(workingDir, cache.sources).chain((package) { | 201 var future = Package.load(workingDir, cache.sources).chain((package) { |
| 202 entrypoint = new Entrypoint(package, cache); | 202 entrypoint = new Entrypoint(package, cache); |
| 203 | 203 |
| 204 try { | 204 try { |
| 205 var commandFuture = onRun(); | 205 var commandFuture = onRun(); |
| 206 if (commandFuture == null) return new Future.immediate(true); | 206 if (commandFuture == null) return new Future.immediate(true); |
| 207 | 207 |
| 208 return commandFuture; | 208 return commandFuture; |
| 209 } catch (var error, var trace) { | 209 } catch (error, trace) { |
| 210 handleError(error, trace); | 210 handleError(error, trace); |
| 211 return new Future.immediate(null); | 211 return new Future.immediate(null); |
| 212 } | 212 } |
| 213 }); | 213 }); |
| 214 future.handleException((e) => handleError(e, future.stackTrace)); | 214 future.handleException((e) => handleError(e, future.stackTrace)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * Override this to perform the specific command. Return a future that | 218 * Override this to perform the specific command. Return a future that |
| 219 * completes when the command is done or fails if the command fails. If the | 219 * completes when the command is done or fails if the command fails. If the |
| 220 * command is synchronous, it may return `null`. | 220 * command is synchronous, it may return `null`. |
| 221 */ | 221 */ |
| 222 abstract Future onRun(); | 222 abstract Future onRun(); |
| 223 | 223 |
| 224 /** Displays usage information for this command. */ | 224 /** Displays usage information for this command. */ |
| 225 void printUsage([String description]) { | 225 void printUsage([String description]) { |
| 226 if (description == null) description = this.description; | 226 if (description == null) description = this.description; |
| 227 print(description); | 227 print(description); |
| 228 print(''); | 228 print(''); |
| 229 print('Usage: $usage'); | 229 print('Usage: $usage'); |
| 230 | 230 |
| 231 var commandUsage = commandParser.getUsage(); | 231 var commandUsage = commandParser.getUsage(); |
| 232 if (!commandUsage.isEmpty()) { | 232 if (!commandUsage.isEmpty()) { |
| 233 print(''); | 233 print(''); |
| 234 print(commandUsage); | 234 print(commandUsage); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 } | 237 } |
| OLD | NEW |