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:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
(...skipping 19 matching lines...) Expand all Loading... |
30 parser.addOption('verbosity', | 30 parser.addOption('verbosity', |
31 help: 'Control output verbosity.', | 31 help: 'Control output verbosity.', |
32 allowed: ['normal', 'io', 'solver', 'all'], | 32 allowed: ['normal', 'io', 'solver', 'all'], |
33 allowedHelp: { | 33 allowedHelp: { |
34 'normal': 'Show errors, warnings, and user messages.', | 34 'normal': 'Show errors, warnings, and user messages.', |
35 'io': 'Also show IO operations.', | 35 'io': 'Also show IO operations.', |
36 'solver': 'Show steps during version resolution.', | 36 'solver': 'Show steps during version resolution.', |
37 'all': 'Show all output including internal tracing messages.' | 37 'all': 'Show all output including internal tracing messages.' |
38 }); | 38 }); |
39 parser.addFlag('verbose', abbr: 'v', negatable: false, | 39 parser.addFlag('verbose', abbr: 'v', negatable: false, |
40 help: 'Shortcut for "--verbosity=all"'); | 40 help: 'Shortcut for "--verbosity=all".'); |
41 return parser; | 41 return parser; |
42 } | 42 } |
43 | 43 |
44 void main() { | 44 void main() { |
45 var globalOptions; | 45 var globalOptions; |
46 try { | 46 try { |
47 globalOptions = pubArgParser.parse(new Options().arguments); | 47 globalOptions = pubArgParser.parse(new Options().arguments); |
48 } on FormatException catch (e) { | 48 } on FormatException catch (e) { |
49 log.error(e.message); | 49 log.error(e.message); |
50 log.error('Run "pub help" to see available options.'); | 50 log.error('Run "pub help" to see available options.'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 if (Platform.environment.containsKey('PUB_CACHE')) { | 84 if (Platform.environment.containsKey('PUB_CACHE')) { |
85 cacheDir = Platform.environment['PUB_CACHE']; | 85 cacheDir = Platform.environment['PUB_CACHE']; |
86 } else if (Platform.operatingSystem == 'windows') { | 86 } else if (Platform.operatingSystem == 'windows') { |
87 var appData = Platform.environment['APPDATA']; | 87 var appData = Platform.environment['APPDATA']; |
88 cacheDir = path.join(appData, 'Pub', 'Cache'); | 88 cacheDir = path.join(appData, 'Pub', 'Cache'); |
89 } else { | 89 } else { |
90 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; | 90 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; |
91 } | 91 } |
92 | 92 |
93 validatePlatform().then((_) { | 93 validatePlatform().then((_) { |
94 var cache = new SystemCache.withSources(cacheDir); | |
95 | |
96 // Select the command. | 94 // Select the command. |
97 var command = PubCommand.commands[globalOptions.rest[0]]; | 95 var command = PubCommand.commands[globalOptions.rest[0]]; |
98 if (command == null) { | 96 if (command == null) { |
99 log.error('Could not find a command named "${globalOptions.rest[0]}".'); | 97 log.error('Could not find a command named "${globalOptions.rest[0]}".'); |
100 log.error('Run "pub help" to see available commands.'); | 98 log.error('Run "pub help" to see available commands.'); |
101 exit(exit_codes.USAGE); | 99 exit(exit_codes.USAGE); |
102 return; | 100 return; |
103 } | 101 } |
104 | 102 |
105 var commandArgs = globalOptions.rest.sublist(1); | 103 var commandArgs = globalOptions.rest.sublist(1); |
106 command.run(cache, globalOptions, commandArgs); | 104 command.run(cacheDir, globalOptions, commandArgs); |
107 }); | 105 }); |
108 } | 106 } |
109 | 107 |
110 /// Checks that pub is running on a supported platform. If it isn't, it prints | 108 /// Checks that pub is running on a supported platform. If it isn't, it prints |
111 /// an error message and exits. Completes when the validation is done. | 109 /// an error message and exits. Completes when the validation is done. |
112 Future validatePlatform() { | 110 Future validatePlatform() { |
113 return new Future.sync(() { | 111 return new Future.sync(() { |
114 if (Platform.operatingSystem != 'windows') return; | 112 if (Platform.operatingSystem != 'windows') return; |
115 | 113 |
116 return runProcess('ver', []).then((result) { | 114 return runProcess('ver', []).then((result) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 for (var name in names) { | 148 for (var name in names) { |
151 buffer.write(' ${padRight(name, length)} ' | 149 buffer.write(' ${padRight(name, length)} ' |
152 '${PubCommand.commands[name].description}\n'); | 150 '${PubCommand.commands[name].description}\n'); |
153 } | 151 } |
154 | 152 |
155 buffer.write('\n'); | 153 buffer.write('\n'); |
156 buffer.write( | 154 buffer.write( |
157 'Use "pub help [command]" for more information about a command.'); | 155 'Use "pub help [command]" for more information about a command.'); |
158 log.message(buffer.toString()); | 156 log.message(buffer.toString()); |
159 } | 157 } |
OLD | NEW |