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 /// The main entrypoint for the pub command line application. | 5 /// The main entrypoint for the pub command line application. |
6 library pub; | 6 library pub; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import '../../pkg/args/lib/args.dart'; | 9 import '../../pkg/args/lib/args.dart'; |
10 import '../../pkg/path/lib/path.dart' as path; | 10 import '../../pkg/path/lib/path.dart' as path; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 default: | 103 default: |
104 // No specific verbosity given, so check for the shortcut. | 104 // No specific verbosity given, so check for the shortcut. |
105 if (globalOptions['verbose']) { | 105 if (globalOptions['verbose']) { |
106 log.showAll(); | 106 log.showAll(); |
107 } else { | 107 } else { |
108 log.showNormal(); | 108 log.showNormal(); |
109 } | 109 } |
110 break; | 110 break; |
111 } | 111 } |
112 | 112 |
113 // TODO(nweiz): Have a fallback for this this out automatically once 1145 is | |
114 // fixed. | |
115 var sdkDir = Platform.environment['DART_SDK']; | |
116 var cacheDir; | 113 var cacheDir; |
117 if (Platform.environment.containsKey('PUB_CACHE')) { | 114 if (Platform.environment.containsKey('PUB_CACHE')) { |
118 cacheDir = Platform.environment['PUB_CACHE']; | 115 cacheDir = Platform.environment['PUB_CACHE']; |
119 } else if (Platform.operatingSystem == 'windows') { | 116 } else if (Platform.operatingSystem == 'windows') { |
120 var appData = Platform.environment['APPDATA']; | 117 var appData = Platform.environment['APPDATA']; |
121 cacheDir = join(appData, 'Pub', 'Cache'); | 118 cacheDir = join(appData, 'Pub', 'Cache'); |
122 } else { | 119 } else { |
123 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; | 120 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; |
124 } | 121 } |
125 | 122 |
126 var cache = new SystemCache.withSources(cacheDir, sdkDir); | 123 var cache = new SystemCache.withSources(cacheDir); |
127 | 124 |
128 // Select the command. | 125 // Select the command. |
129 var command = pubCommands[globalOptions.rest[0]]; | 126 var command = pubCommands[globalOptions.rest[0]]; |
130 if (command == null) { | 127 if (command == null) { |
131 log.error('Could not find a command named "${globalOptions.rest[0]}".'); | 128 log.error('Could not find a command named "${globalOptions.rest[0]}".'); |
132 log.error('Run "pub help" to see available commands.'); | 129 log.error('Run "pub help" to see available commands.'); |
133 exit(exit_codes.USAGE); | 130 exit(exit_codes.USAGE); |
134 return; | 131 return; |
135 } | 132 } |
136 | 133 |
137 var commandArgs = | 134 var commandArgs = |
138 globalOptions.rest.getRange(1, globalOptions.rest.length - 1); | 135 globalOptions.rest.getRange(1, globalOptions.rest.length - 1); |
139 command.run(cache, globalOptions, commandArgs); | 136 command.run(cache, globalOptions, commandArgs); |
140 } | 137 } |
141 | 138 |
142 /// Displays usage information for the app. | 139 /// Displays usage information for the app. |
143 void printUsage([String description = 'Pub is a package manager for Dart.']) { | 140 void printUsage([String description = 'Pub is a package manager for Dart.']) { |
144 // Build up a buffer so it shows up as a single log entry. | 141 // Build up a buffer so it shows up as a single log entry. |
145 var buffer = new StringBuffer(); | 142 var buffer = new StringBuffer(); |
146 buffer.add(description); | 143 buffer.add(description); |
147 buffer.add('\n\n'); | 144 buffer.add('\n\n'); |
148 buffer.add('Usage: pub command [arguments]\n\n'); | 145 buffer.add('Usage: pub command [arguments]\n\n'); |
149 buffer.add('Global options:\n'); | 146 buffer.add('Global options:\n'); |
150 buffer.add('${pubArgParser.getUsage()}\n\n'); | 147 buffer.add('${pubArgParser.getUsage()}\n\n'); |
151 | 148 |
152 // Show the commands sorted. | 149 // Show the commands sorted. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // Explicitly exit on success to ensure that any dangling dart:io handles | 273 // Explicitly exit on success to ensure that any dangling dart:io handles |
277 // don't cause the process to never terminate. | 274 // don't cause the process to never terminate. |
278 .then((_) => exit(0)); | 275 .then((_) => exit(0)); |
279 } | 276 } |
280 | 277 |
281 /// Override this to perform the specific command. Return a future that | 278 /// Override this to perform the specific command. Return a future that |
282 /// completes when the command is done or fails if the command fails. If the | 279 /// completes when the command is done or fails if the command fails. If the |
283 /// command is synchronous, it may return `null`. | 280 /// command is synchronous, it may return `null`. |
284 Future onRun(); | 281 Future onRun(); |
285 | 282 |
286 /// Displays usage information for this command. | 283 /// Displays usage information for this command. |
287 void printUsage([String description]) { | 284 void printUsage([String description]) { |
288 if (description == null) description = this.description; | 285 if (description == null) description = this.description; |
289 | 286 |
290 var buffer = new StringBuffer(); | 287 var buffer = new StringBuffer(); |
291 buffer.add('$description\n\nUsage: $usage'); | 288 buffer.add('$description\n\nUsage: $usage'); |
292 | 289 |
293 var commandUsage = commandParser.getUsage(); | 290 var commandUsage = commandParser.getUsage(); |
294 if (!commandUsage.isEmpty) { | 291 if (!commandUsage.isEmpty) { |
295 buffer.add('\n'); | 292 buffer.add('\n'); |
296 buffer.add(commandUsage); | 293 buffer.add(commandUsage); |
297 } | 294 } |
298 | 295 |
299 log.message(buffer.toString()); | 296 log.message(buffer.toString()); |
300 } | 297 } |
301 | 298 |
302 /// Returns the appropriate exit code for [exception], falling back on 1 if no | 299 /// Returns the appropriate exit code for [exception], falling back on 1 if no |
303 /// appropriate exit code could be found. | 300 /// appropriate exit code could be found. |
304 int _chooseExitCode(exception) { | 301 int _chooseExitCode(exception) { |
305 if (exception is HttpException || exception is HttpParserException || | 302 if (exception is HttpException || exception is HttpParserException || |
306 exception is SocketIOException || exception is PubHttpException) { | 303 exception is SocketIOException || exception is PubHttpException) { |
307 return exit_codes.UNAVAILABLE; | 304 return exit_codes.UNAVAILABLE; |
308 } else if (exception is FormatException) { | 305 } else if (exception is FormatException) { |
309 return exit_codes.DATA; | 306 return exit_codes.DATA; |
310 } else { | 307 } else { |
311 return 1; | 308 return 1; |
312 } | 309 } |
313 } | 310 } |
314 } | 311 } |
OLD | NEW |