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