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

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

Issue 797473002: Add a CommandRunner class for dispatching commands to args. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years 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 | Annotate | Revision Log
OLDNEW
(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 usage => "${runner.executableName} help [command]";
17
18 void run() {
19 // Show the default help if no command was specified.
20 if (options.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 options.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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698