| 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 10 matching lines...) Expand all Loading... |
| 21 #import('package.dart'); | 21 #import('package.dart'); |
| 22 #import('pubspec.dart'); | 22 #import('pubspec.dart'); |
| 23 #import('repo_source.dart'); | 23 #import('repo_source.dart'); |
| 24 #import('sdk_source.dart'); | 24 #import('sdk_source.dart'); |
| 25 #import('source.dart'); | 25 #import('source.dart'); |
| 26 #import('source_registry.dart'); | 26 #import('source_registry.dart'); |
| 27 #import('system_cache.dart'); | 27 #import('system_cache.dart'); |
| 28 #import('utils.dart'); | 28 #import('utils.dart'); |
| 29 #import('version.dart'); | 29 #import('version.dart'); |
| 30 | 30 |
| 31 Version get pubVersion() => new Version(0, 0, 0); | 31 Version get pubVersion => new Version(0, 0, 0); |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * The commands that Pub understands. | 34 * The commands that Pub understands. |
| 35 */ | 35 */ |
| 36 Map<String, PubCommand> get pubCommands() => { | 36 Map<String, PubCommand> get pubCommands => { |
| 37 'help': new HelpCommand(), | 37 'help': new HelpCommand(), |
| 38 'list': new ListCommand(), | 38 'list': new ListCommand(), |
| 39 'install': new InstallCommand(), | 39 'install': new InstallCommand(), |
| 40 'update': new UpdateCommand(), | 40 'update': new UpdateCommand(), |
| 41 'version': new VersionCommand() | 41 'version': new VersionCommand() |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * The parser for arguments that are global to Pub rather than specific to a | 45 * The parser for arguments that are global to Pub rather than specific to a |
| 46 * single command. | 46 * single command. |
| 47 */ | 47 */ |
| 48 ArgParser get pubArgParser() { | 48 ArgParser get pubArgParser { |
| 49 var parser = new ArgParser(); | 49 var parser = new ArgParser(); |
| 50 parser.addFlag('help', abbr: 'h', negatable: false, | 50 parser.addFlag('help', abbr: 'h', negatable: false, |
| 51 help: 'Prints this usage information'); | 51 help: 'Prints this usage information'); |
| 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() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 class PubCommand { | 143 class PubCommand { |
| 144 SystemCache cache; | 144 SystemCache cache; |
| 145 ArgResults globalOptions; | 145 ArgResults globalOptions; |
| 146 ArgResults commandOptions; | 146 ArgResults commandOptions; |
| 147 | 147 |
| 148 Entrypoint entrypoint; | 148 Entrypoint entrypoint; |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * A one-line description of this command. | 151 * A one-line description of this command. |
| 152 */ | 152 */ |
| 153 abstract String get description(); | 153 abstract String get description; |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * How to invoke this command (e.g. `"pub install [package]"`). | 156 * How to invoke this command (e.g. `"pub install [package]"`). |
| 157 */ | 157 */ |
| 158 abstract String get usage(); | 158 abstract String get usage; |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * Override this to define command-specific options. The results will be made | 161 * Override this to define command-specific options. The results will be made |
| 162 * available in [commandOptions]. | 162 * available in [commandOptions]. |
| 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 } catch (FormatException e) { |
| 174 this.printUsage(description: e.message); | 174 this.printUsage(description: e.message); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |