| 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 library pub.command.help; | 5 library pub.command.help; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../command.dart'; | 9 import '../command.dart'; |
| 10 import '../exit_codes.dart' as exit_codes; | |
| 11 import '../io.dart'; | |
| 12 import '../log.dart' as log; | |
| 13 | 10 |
| 14 /// Handles the `help` pub command. | 11 /// Handles the `help` pub command. |
| 15 class HelpCommand extends PubCommand { | 12 class HelpCommand extends PubCommand { |
| 16 String get description => "Display help information for Pub."; | 13 String get description => "Display help information for Pub."; |
| 17 String get usage => "pub help [command]"; | 14 String get usage => "pub help [command]"; |
| 18 bool get requiresEntrypoint => false; | 15 bool get requiresEntrypoint => false; |
| 19 bool get takesArguments => true; | 16 bool get takesArguments => true; |
| 20 | 17 |
| 21 Future onRun() { | 18 Future onRun() { |
| 19 // Show the default help if no command was specified. |
| 22 if (commandOptions.rest.isEmpty) { | 20 if (commandOptions.rest.isEmpty) { |
| 23 PubCommand.printGlobalUsage(); | 21 PubCommand.printGlobalUsage(); |
| 24 } else { | 22 return null; |
| 25 var name = commandOptions.rest[0]; | 23 } |
| 26 var command = PubCommand.commands[name]; | 24 |
| 27 if (command == null) { | 25 // Walk the command tree to show help for the selected command or |
| 28 log.error('Could not find a command named "$name".'); | 26 // subcommand. |
| 29 log.error('Run "pub help" to see available commands.'); | 27 var commands = PubCommand.mainCommands; |
| 30 return flushThenExit(exit_codes.USAGE); | 28 var command = null; |
| 29 var commandString = "pub"; |
| 30 |
| 31 for (var name in commandOptions.rest) { |
| 32 if (commands.isEmpty) { |
| 33 command.usageError( |
| 34 'Command "$commandString" does not expect a subcommand.'); |
| 31 } | 35 } |
| 32 | 36 |
| 33 command.printUsage(); | 37 if (commands[name] == null) { |
| 38 if (command == null) { |
| 39 PubCommand.usageErrorWithCommands(commands, |
| 40 'Could not find a command named "$name".'); |
| 41 } |
| 42 |
| 43 command.usageError( |
| 44 'Could not find a subcommand named "$name" for "$commandString".'); |
| 45 } |
| 46 |
| 47 command = commands[name]; |
| 48 commands = command.subcommands; |
| 49 commandString += " $name"; |
| 34 } | 50 } |
| 51 |
| 52 command.printUsage(); |
| 35 } | 53 } |
| 36 } | 54 } |
| OLD | NEW |