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

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: 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
1 // Copyright (c) 2012, 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 pub.command.help; 5 library args.help_command;
6 6
7 import 'dart:async'; 7 import 'command_runner.dart';
8 8
9 import '../command.dart'; 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";
Bob Nystrom 2014/12/11 20:25:31 Why not make this a getter too?
nweiz 2014/12/11 23:55:24 I don't like constant-valued getters when fields w
Bob Nystrom 2014/12/12 18:13:22 I know you feel that way, but I still don't unders
14 String get description =>
15 "Display help information for ${runner.executableName}.";
16 String get usage => "${runner.executableName} help [command]";
10 17
11 /// Handles the `help` pub command. 18 HelpCommand();
Bob Nystrom 2014/12/11 20:25:31 Delete.
nweiz 2014/12/11 23:55:24 Done.
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 19
17 Future onRun() { 20 void run() {
18 // Show the default help if no command was specified. 21 // Show the default help if no command was specified.
19 if (commandOptions.rest.isEmpty) { 22 if (options.rest.isEmpty) {
20 PubCommand.printGlobalUsage(); 23 runner.printUsage();
21 return null; 24 return;
22 } 25 }
23 26
24 // Walk the command tree to show help for the selected command or 27 // Walk the command tree to show help for the selected command or
25 // subcommand. 28 // subcommand.
26 var commands = PubCommand.mainCommands; 29 var commands = runner.topLevelCommands;
27 var command = null; 30 var command = null;
28 var commandString = "pub"; 31 var commandString = runner.executableName;
29 32
30 for (var name in commandOptions.rest) { 33 for (var name in options.rest) {
31 if (commands.isEmpty) { 34 if (commands.isEmpty) {
32 command.usageError( 35 command.usageError(
33 'Command "$commandString" does not expect a subcommand.'); 36 'Command "$commandString" does not expect a subcommand.');
34 } 37 }
35 38
36 if (commands[name] == null) { 39 if (commands[name] == null) {
37 if (command == null) { 40 if (command == null) {
38 PubCommand.usageErrorWithCommands(commands, 41 runner.usageError('Could not find a command named "$name".');
39 'Could not find a command named "$name".');
40 } 42 }
41 43
42 command.usageError( 44 command.usageError(
43 'Could not find a subcommand named "$name" for "$commandString".'); 45 'Could not find a subcommand named "$name" for "$commandString".');
44 } 46 }
45 47
46 command = commands[name]; 48 command = commands[name];
47 commands = command.subcommands; 49 commands = command.subcommands;
48 commandString += " $name"; 50 commandString += " $name";
49 } 51 }
50 52
51 command.printUsage(); 53 command.printUsage();
52 return null;
53 } 54 }
54 } 55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698