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 | 7 |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 if (options['version']) { | 31 if (options['version']) { |
32 log.message('Pub ${sdk.version}'); | 32 log.message('Pub ${sdk.version}'); |
33 return; | 33 return; |
34 } | 34 } |
35 | 35 |
36 if (options['help']) { | 36 if (options['help']) { |
37 PubCommand.printGlobalUsage(); | 37 PubCommand.printGlobalUsage(); |
38 return; | 38 return; |
39 } | 39 } |
40 | 40 |
41 if (options.command == null) { | |
42 if (options.rest.isEmpty) { | |
43 // No command was chosen. | |
44 PubCommand.printGlobalUsage(); | |
45 } else { | |
46 log.error('Could not find a command named "${options.rest[0]}".'); | |
47 log.error('Run "pub help" to see available commands.'); | |
48 flushThenExit(exit_codes.USAGE); | |
49 } | |
50 return; | |
51 } | |
52 | |
53 if (options['trace']) { | 41 if (options['trace']) { |
54 log.recordTranscript(); | 42 log.recordTranscript(); |
55 } | 43 } |
56 | 44 |
57 switch (options['verbosity']) { | 45 switch (options['verbosity']) { |
58 case 'normal': log.showNormal(); break; | 46 case 'normal': log.showNormal(); break; |
59 case 'io': log.showIO(); break; | 47 case 'io': log.showIO(); break; |
60 case 'solver': log.showSolver(); break; | 48 case 'solver': log.showSolver(); break; |
61 case 'all': log.showAll(); break; | 49 case 'all': log.showAll(); break; |
62 default: | 50 default: |
(...skipping 11 matching lines...) Expand all Loading... | |
74 var cacheDir; | 62 var cacheDir; |
75 if (Platform.environment.containsKey('PUB_CACHE')) { | 63 if (Platform.environment.containsKey('PUB_CACHE')) { |
76 cacheDir = Platform.environment['PUB_CACHE']; | 64 cacheDir = Platform.environment['PUB_CACHE']; |
77 } else if (Platform.operatingSystem == 'windows') { | 65 } else if (Platform.operatingSystem == 'windows') { |
78 var appData = Platform.environment['APPDATA']; | 66 var appData = Platform.environment['APPDATA']; |
79 cacheDir = path.join(appData, 'Pub', 'Cache'); | 67 cacheDir = path.join(appData, 'Pub', 'Cache'); |
80 } else { | 68 } else { |
81 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; | 69 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; |
82 } | 70 } |
83 | 71 |
84 validatePlatform().then((_) { | 72 validatePlatform().then((_) { |
nweiz
2014/01/31 21:42:06
Nit: =>
Bob Nystrom
2014/02/01 01:49:32
Done.
| |
85 PubCommand.commands[options.command.name].run(cacheDir, options, arguments); | 73 runCommand(cacheDir, options, arguments); |
86 }); | 74 }); |
87 } | 75 } |
88 | 76 |
77 void runCommand(String cacheDir, ArgResults mainOptions, | |
nweiz
2014/01/31 21:42:06
Document this.
Bob Nystrom
2014/02/01 01:49:32
Done.
| |
78 List<String> arguments) { | |
79 // Walk down the commands and subcommands until we hit a leaf. | |
80 var commands = PubCommand.mainCommands; | |
81 var command; | |
82 var commandString = "pub"; | |
83 var options = mainOptions; | |
84 | |
85 _usageError(message) { | |
86 var buffer = new StringBuffer(); | |
87 buffer.writeln(message); | |
88 PubCommand.listCommands(commands, buffer, isSubcommand: command != null); | |
89 log.error(buffer); | |
90 flushThenExit(exit_codes.USAGE); | |
91 } | |
92 | |
93 while (commands.isNotEmpty) { | |
94 if (options['help']) { | |
95 command.printUsage(); | |
96 return; | |
97 } | |
98 | |
99 if (options.command == null) { | |
100 if (options.rest.isEmpty) { | |
101 if (command == null) { | |
102 // No top-level command was chosen. | |
103 PubCommand.printGlobalUsage(); | |
104 } else { | |
105 _usageError('Missing subcommand for "$commandString".'); | |
106 } | |
107 } else { | |
108 if (command == null) { | |
109 _usageError('Could not find a command named "${options.rest[0]}".'); | |
nweiz
2014/01/31 21:42:06
"find" seems weird here -- it's not like the comma
Bob Nystrom
2014/02/01 01:49:32
<shrug> It's the same message we had before. I thi
| |
110 } else { | |
111 _usageError('Could not find a subcommand named "${options.rest[0]}" ' | |
112 'for "$commandString".'); | |
113 } | |
114 } | |
115 | |
116 return; | |
117 } | |
118 | |
119 // Step into the command. | |
120 options = options.command; | |
121 command = commands[options.name]; | |
122 commands = command.subcommands; | |
123 commandString += " ${options.name}"; | |
124 } | |
125 | |
126 command.run(cacheDir, mainOptions, options, arguments); | |
127 } | |
128 | |
89 /// Checks that pub is running on a supported platform. If it isn't, it prints | 129 /// Checks that pub is running on a supported platform. If it isn't, it prints |
90 /// an error message and exits. Completes when the validation is done. | 130 /// an error message and exits. Completes when the validation is done. |
91 Future validatePlatform() { | 131 Future validatePlatform() { |
92 return syncFuture(() { | 132 return syncFuture(() { |
93 if (Platform.operatingSystem != 'windows') return null; | 133 if (Platform.operatingSystem != 'windows') return null; |
94 | 134 |
95 return runProcess('ver', []).then((result) { | 135 return runProcess('ver', []).then((result) { |
96 if (result.stdout.join('\n').contains('XP')) { | 136 if (result.stdout.join('\n').contains('XP')) { |
97 log.error('Sorry, but pub is not supported on Windows XP.'); | 137 log.error('Sorry, but pub is not supported on Windows XP.'); |
98 return flushThenExit(exit_codes.USAGE); | 138 return flushThenExit(exit_codes.USAGE); |
99 } | 139 } |
100 }); | 140 }); |
101 }); | 141 }); |
102 } | 142 } |
OLD | NEW |