OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 args.help_command; | |
6 | |
7 import '../command_runner.dart'; | |
8 | |
9 /// The built-in help command that's added to every [CommandRunner]. | |
10 /// | |
11 /// This command displays help information for the various subcommands. | |
12 class HelpCommand extends Command { | |
13 final name = "help"; | |
14 String get description => | |
15 "Display help information for ${runner.executableName}."; | |
16 String get invocation => "${runner.executableName} help [command]"; | |
17 | |
18 void run() { | |
19 // Show the default help if no command was specified. | |
20 if (argResults.rest.isEmpty) { | |
21 runner.printUsage(); | |
22 return; | |
23 } | |
24 | |
25 // Walk the command tree to show help for the selected command or | |
26 // subcommand. | |
27 var commands = runner.commands; | |
28 var command = null; | |
29 var commandString = runner.executableName; | |
30 | |
31 for (var name in argResults.rest) { | |
32 if (commands.isEmpty) { | |
33 command.usageException( | |
34 'Command "$commandString" does not expect a subcommand.'); | |
35 } | |
36 | |
37 if (commands[name] == null) { | |
38 if (command == null) { | |
39 runner.usageException('Could not find a command named "$name".'); | |
40 } | |
41 | |
42 command.usageException( | |
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 } | |
53 } | |
OLD | NEW |