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

Unified Diff: sdk/lib/_internal/pub/lib/src/command/help.dart

Issue 138723005: Support subcommands in pub and pub help. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Infer hiddenness from subcommands. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/lib/src/command/help.dart
diff --git a/sdk/lib/_internal/pub/lib/src/command/help.dart b/sdk/lib/_internal/pub/lib/src/command/help.dart
index 91181754d3420882f9a398b0e5007598b224929c..c1889ff2057122b812064bdd684a8dde8b160dda 100644
--- a/sdk/lib/_internal/pub/lib/src/command/help.dart
+++ b/sdk/lib/_internal/pub/lib/src/command/help.dart
@@ -7,9 +7,6 @@ library pub.command.help;
import 'dart:async';
import '../command.dart';
-import '../exit_codes.dart' as exit_codes;
-import '../io.dart';
-import '../log.dart' as log;
/// Handles the `help` pub command.
class HelpCommand extends PubCommand {
@@ -19,18 +16,39 @@ class HelpCommand extends PubCommand {
bool get takesArguments => true;
Future onRun() {
+ // Show the default help if no command was specified.
if (commandOptions.rest.isEmpty) {
PubCommand.printGlobalUsage();
- } else {
- var name = commandOptions.rest[0];
- var command = PubCommand.commands[name];
- if (command == null) {
- log.error('Could not find a command named "$name".');
- log.error('Run "pub help" to see available commands.');
- return flushThenExit(exit_codes.USAGE);
+ return null;
+ }
+
+ // Walk the command tree to show help for the selected command or
+ // subcommand.
+ var commands = PubCommand.mainCommands;
+ var command = null;
+ var commandString = "pub";
+
+ for (var name in commandOptions.rest) {
+ if (commands.isEmpty) {
+ command.usageError(
+ 'Command "$commandString" does not expect a subcommand.');
}
- command.printUsage();
+ if (commands[name] == null) {
+ if (command == null) {
+ PubCommand.usageErrorWithCommands(commands,
+ 'Could not find a command named "$name".');
+ }
+
+ command.usageError(
+ 'Could not find a subcommand named "$name" for "$commandString".');
+ }
+
+ command = commands[name];
+ commands = command.subcommands;
+ commandString += " $name";
}
+
+ command.printUsage();
}
}
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/command/cache_list.dart ('k') | sdk/lib/_internal/pub/lib/src/command/lish.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698