Index: sdk/lib/_internal/pub/bin/pub.dart |
diff --git a/sdk/lib/_internal/pub/bin/pub.dart b/sdk/lib/_internal/pub/bin/pub.dart |
index a589dcc8403a9ac31593a593ad2afb4545c1f627..533efdbaef9e36ca94dc4b9c1436f877603bbb58 100644 |
--- a/sdk/lib/_internal/pub/bin/pub.dart |
+++ b/sdk/lib/_internal/pub/bin/pub.dart |
@@ -38,18 +38,6 @@ void main(List<String> arguments) { |
return; |
} |
- if (options.command == null) { |
- if (options.rest.isEmpty) { |
- // No command was chosen. |
- PubCommand.printGlobalUsage(); |
- } else { |
- log.error('Could not find a command named "${options.rest[0]}".'); |
- log.error('Run "pub help" to see available commands.'); |
- flushThenExit(exit_codes.USAGE); |
- } |
- return; |
- } |
- |
if (options['trace']) { |
log.recordTranscript(); |
} |
@@ -82,10 +70,62 @@ void main(List<String> arguments) { |
} |
validatePlatform().then((_) { |
nweiz
2014/01/31 21:42:06
Nit: =>
Bob Nystrom
2014/02/01 01:49:32
Done.
|
- PubCommand.commands[options.command.name].run(cacheDir, options, arguments); |
+ runCommand(cacheDir, options, arguments); |
}); |
} |
+void runCommand(String cacheDir, ArgResults mainOptions, |
nweiz
2014/01/31 21:42:06
Document this.
Bob Nystrom
2014/02/01 01:49:32
Done.
|
+ List<String> arguments) { |
+ // Walk down the commands and subcommands until we hit a leaf. |
+ var commands = PubCommand.mainCommands; |
+ var command; |
+ var commandString = "pub"; |
+ var options = mainOptions; |
+ |
+ _usageError(message) { |
+ var buffer = new StringBuffer(); |
+ buffer.writeln(message); |
+ PubCommand.listCommands(commands, buffer, isSubcommand: command != null); |
+ log.error(buffer); |
+ flushThenExit(exit_codes.USAGE); |
+ } |
+ |
+ while (commands.isNotEmpty) { |
+ if (options['help']) { |
+ command.printUsage(); |
+ return; |
+ } |
+ |
+ if (options.command == null) { |
+ if (options.rest.isEmpty) { |
+ if (command == null) { |
+ // No top-level command was chosen. |
+ PubCommand.printGlobalUsage(); |
+ } else { |
+ _usageError('Missing subcommand for "$commandString".'); |
+ } |
+ } else { |
+ if (command == null) { |
+ _usageError('Could not find a command named "${options.rest[0]}".'); |
nweiz
2014/01/31 21:42:06
"find" seems weird here -- it's not like the comma
Bob Nystrom
2014/02/01 01:49:32
<shrug> It's the same message we had before. I thi
|
+ } else { |
+ _usageError('Could not find a subcommand named "${options.rest[0]}" ' |
+ 'for "$commandString".'); |
+ } |
+ } |
+ |
+ return; |
+ } |
+ |
+ // Step into the command. |
+ options = options.command; |
+ command = commands[options.name]; |
+ commands = command.subcommands; |
+ commandString += " ${options.name}"; |
+ } |
+ |
+ command.run(cacheDir, mainOptions, options, arguments); |
+} |
+ |
/// Checks that pub is running on a supported platform. If it isn't, it prints |
/// an error message and exits. Completes when the validation is done. |
Future validatePlatform() { |