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

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

Issue 428313004: Support activating packages from local paths. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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/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..fbb0c5c1a859a6fed1773230043c001fbe2dddc4 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,63 @@ 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 [--source source] <package> [version]";
nweiz 2014/07/31 20:01:53 Long line. Also, normally we don't include options
Bob Nystrom 2014/08/04 23:41:50 Tweaked it a bit.
bool get takesArguments => true;
+ GlobalActivateCommand() {
+ commandParser.addOption("source",
+ abbr: "s",
+ help: "The source used to find the package.",
+ allowed: ["git", "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 "git":
+ // Parse the git ref.
+ // TODO(bob): Test.
nweiz 2014/07/31 20:01:53 Remove this
Bob Nystrom 2014/08/04 23:41:50 Done.
+ var ref = readArg("Must provide a Git ref for the package.");
nweiz 2014/07/31 20:01:53 Why does the user have to supply a ref for git? Gi
Bob Nystrom 2014/08/04 23:41:50 I think I just got my terminology confused here. T
+ validateNoExtraArgs();
+ return globals.activateGit(package, ref);
+
+ case "hosted":
+ // Parse the version constraint, if there is one.
+ var constraint = VersionConstraint.any;
+ if (args.isNotEmpty) {
+ try {
+ constraint = new VersionConstraint.parse(readArg(""));
nweiz 2014/07/31 20:01:53 Passing an empty string to parseArg here reads wei
Bob Nystrom 2014/08/04 23:41:50 Done.
+ } 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";
}
}

Powered by Google App Engine
This is Rietveld 408576698