| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
| 11 | 11 |
| 12 import '../lib/src/command.dart'; | 12 import '../lib/src/command.dart'; |
| 13 import '../lib/src/exit_codes.dart' as exit_codes; | 13 import '../lib/src/exit_codes.dart' as exit_codes; |
| 14 import '../lib/src/io.dart'; | 14 import '../lib/src/io.dart'; |
| 15 import '../lib/src/log.dart' as log; | 15 import '../lib/src/log.dart' as log; |
| 16 import '../lib/src/sdk.dart' as sdk; | 16 import '../lib/src/sdk.dart' as sdk; |
| 17 import '../lib/src/utils.dart'; | 17 import '../lib/src/utils.dart'; |
| 18 | 18 |
| 19 final pubArgParser = initArgParser(); | 19 final pubArgParser = initArgParser(); |
| 20 | 20 |
| 21 void main() { | 21 void main(List<String> arguments) { |
| 22 ArgResults options; | 22 ArgResults options; |
| 23 | 23 |
| 24 try { | 24 try { |
| 25 options = pubArgParser.parse(new Options().arguments); | 25 options = pubArgParser.parse(arguments); |
| 26 } on FormatException catch (e) { | 26 } on FormatException catch (e) { |
| 27 log.error(e.message); | 27 log.error(e.message); |
| 28 log.error('Run "pub help" to see available options.'); | 28 log.error('Run "pub help" to see available options.'); |
| 29 flushThenExit(exit_codes.USAGE); | 29 flushThenExit(exit_codes.USAGE); |
| 30 return; | 30 return; |
| 31 } | 31 } |
| 32 | 32 |
| 33 if (options['version']) { | 33 if (options['version']) { |
| 34 log.message('Pub ${sdk.version}'); | 34 log.message('Pub ${sdk.version}'); |
| 35 return; | 35 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (Platform.environment.containsKey('PUB_CACHE')) { | 77 if (Platform.environment.containsKey('PUB_CACHE')) { |
| 78 cacheDir = Platform.environment['PUB_CACHE']; | 78 cacheDir = Platform.environment['PUB_CACHE']; |
| 79 } else if (Platform.operatingSystem == 'windows') { | 79 } else if (Platform.operatingSystem == 'windows') { |
| 80 var appData = Platform.environment['APPDATA']; | 80 var appData = Platform.environment['APPDATA']; |
| 81 cacheDir = path.join(appData, 'Pub', 'Cache'); | 81 cacheDir = path.join(appData, 'Pub', 'Cache'); |
| 82 } else { | 82 } else { |
| 83 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; | 83 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; |
| 84 } | 84 } |
| 85 | 85 |
| 86 validatePlatform().then((_) { | 86 validatePlatform().then((_) { |
| 87 PubCommand.commands[options.command.name].run(cacheDir, options); | 87 PubCommand.commands[options.command.name].run(cacheDir, options, arguments); |
| 88 }); | 88 }); |
| 89 } | 89 } |
| 90 | 90 |
| 91 ArgParser initArgParser() { | 91 ArgParser initArgParser() { |
| 92 var argParser = new ArgParser(); | 92 var argParser = new ArgParser(); |
| 93 | 93 |
| 94 // Add the global options. | 94 // Add the global options. |
| 95 argParser.addFlag('help', abbr: 'h', negatable: false, | 95 argParser.addFlag('help', abbr: 'h', negatable: false, |
| 96 help: 'Print this usage information.'); | 96 help: 'Print this usage information.'); |
| 97 argParser.addFlag('version', negatable: false, | 97 argParser.addFlag('version', negatable: false, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 for (var name in names) { | 165 for (var name in names) { |
| 166 buffer.write(' ${padRight(name, length)} ' | 166 buffer.write(' ${padRight(name, length)} ' |
| 167 '${PubCommand.commands[name].description}\n'); | 167 '${PubCommand.commands[name].description}\n'); |
| 168 } | 168 } |
| 169 | 169 |
| 170 buffer.write('\n'); | 170 buffer.write('\n'); |
| 171 buffer.write( | 171 buffer.write( |
| 172 'Use "pub help [command]" for more information about a command.'); | 172 'Use "pub help [command]" for more information about a command.'); |
| 173 log.message(buffer.toString()); | 173 log.message(buffer.toString()); |
| 174 } | 174 } |
| OLD | NEW |