Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: lib/src/help_command.dart

Issue 1748333005: Make it strong mode clean. (Closed) Base URL: https://github.com/dart-lang/args.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import '../command_runner.dart'; 5 import '../command_runner.dart';
6 6
7 /// The built-in help command that's added to every [CommandRunner]. 7 /// The built-in help command that's added to every [CommandRunner].
8 /// 8 ///
9 /// This command displays help information for the various subcommands. 9 /// This command displays help information for the various subcommands.
10 class HelpCommand extends Command { 10 class HelpCommand extends Command {
11 final name = "help"; 11 final name = "help";
12 String get description => 12 String get description =>
13 "Display help information for ${runner.executableName}."; 13 "Display help information for ${runner.executableName}.";
14 String get invocation => "${runner.executableName} help [command]"; 14 String get invocation => "${runner.executableName} help [command]";
15 15
16 void run() { 16 void run() {
17 // Show the default help if no command was specified. 17 // Show the default help if no command was specified.
18 if (argResults.rest.isEmpty) { 18 if (argResults.rest.isEmpty) {
19 runner.printUsage(); 19 runner.printUsage();
20 return; 20 return;
21 } 21 }
22 22
23 // Walk the command tree to show help for the selected command or 23 // Walk the command tree to show help for the selected command or
24 // subcommand. 24 // subcommand.
25 var commands = runner.commands; 25 var commands = runner.commands;
26 var command = null; 26 Command command;
27 var commandString = runner.executableName; 27 var commandString = runner.executableName;
28 28
29 for (var name in argResults.rest) { 29 for (var name in argResults.rest) {
30 if (commands.isEmpty) { 30 if (commands.isEmpty) {
31 command.usageException( 31 command.usageException(
32 'Command "$commandString" does not expect a subcommand.'); 32 'Command "$commandString" does not expect a subcommand.');
33 } 33 }
34 34
35 if (commands[name] == null) { 35 if (commands[name] == null) {
36 if (command == null) { 36 if (command == null) {
37 runner.usageException('Could not find a command named "$name".'); 37 runner.usageException('Could not find a command named "$name".');
38 } 38 }
39 39
40 command.usageException( 40 command.usageException(
41 'Could not find a subcommand named "$name" for "$commandString".'); 41 'Could not find a subcommand named "$name" for "$commandString".');
42 } 42 }
43 43
44 command = commands[name]; 44 command = commands[name];
45 commands = command.subcommands; 45 commands = command.subcommands;
46 commandString += " $name"; 46 commandString += " $name";
47 } 47 }
48 48
49 command.printUsage(); 49 command.printUsage();
50 } 50 }
51 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698