Index: sdk/lib/_internal/pub/lib/src/command/global_activate.dart |
diff --git a/sdk/lib/_internal/pub/lib/src/command/global_activate.dart b/sdk/lib/_internal/pub/lib/src/command/global_activate.dart |
index 6fc25e3020d4978e9b1b39330ec8a50bd12be8e7..98ba40e52d2c9fd87929e3c59cda7827ba8a57c0 100644 |
--- a/sdk/lib/_internal/pub/lib/src/command/global_activate.dart |
+++ b/sdk/lib/_internal/pub/lib/src/command/global_activate.dart |
@@ -13,34 +13,56 @@ import '../version.dart'; |
/// Handles the `global activate` pub command. |
class GlobalActivateCommand extends PubCommand { |
String get description => "Make a package's executables globally available."; |
- String get usage => "pub global activate <package> [version]"; |
+ String get usage => "pub global activate <package...>"; |
bool get takesArguments => true; |
+ GlobalActivateCommand() { |
+ commandParser.addOption("source", |
+ abbr: "s", |
+ help: "The source used to find the package.", |
+ allowed: ["hosted", "path"], |
+ defaultsTo: "hosted"); |
+ } |
+ |
Future onRun() { |
- // Make sure there is a package. |
- if (commandOptions.rest.isEmpty) { |
- usageError("No package to activate given."); |
+ var args = commandOptions.rest; |
+ |
+ readArg([String error]) { |
+ if (args.isEmpty) usageError(error); |
+ var arg = args.first; |
+ args = args.skip(1); |
+ return arg; |
} |
- // Don't allow extra arguments. |
- if (commandOptions.rest.length > 2) { |
- var unexpected = commandOptions.rest.skip(2).map((arg) => '"$arg"'); |
+ validateNoExtraArgs() { |
+ if (args.isEmpty) return; |
+ var unexpected = args.map((arg) => '"$arg"'); |
var arguments = pluralize("argument", unexpected.length); |
usageError("Unexpected $arguments ${toSentence(unexpected)}."); |
} |
- var package = commandOptions.rest.first; |
+ var package = readArg("No package to activate given."); |
+ |
+ switch (commandOptions["source"]) { |
+ case "hosted": |
+ // Parse the version constraint, if there is one. |
+ var constraint = VersionConstraint.any; |
+ if (args.isNotEmpty) { |
+ try { |
+ constraint = new VersionConstraint.parse(readArg()); |
+ } on FormatException catch (error) { |
+ usageError(error.message); |
+ } |
+ } |
+ |
+ validateNoExtraArgs(); |
+ return globals.activateHosted(package, constraint); |
- // Parse the version constraint, if there is one. |
- var constraint = VersionConstraint.any; |
- if (commandOptions.rest.length == 2) { |
- try { |
- constraint = new VersionConstraint.parse(commandOptions.rest[1]); |
- } on FormatException catch (error) { |
- usageError(error.message); |
- } |
+ case "path": |
+ validateNoExtraArgs(); |
+ return globals.activatePath(package); |
} |
- return globals.activate(package, constraint); |
+ throw "unreachable"; |
} |
} |