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