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

Unified Diff: sdk/lib/_internal/pub/lib/src/global_packages.dart

Issue 341433009: Pub global deactivate command. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/global_packages.dart
diff --git a/sdk/lib/_internal/pub/lib/src/global_packages.dart b/sdk/lib/_internal/pub/lib/src/global_packages.dart
index c0ab46f8e23d315b090b3b5214f6919ad29777c1..20aaf8cff5cb6fad6d6166feef8e21bc42d8ed51 100644
--- a/sdk/lib/_internal/pub/lib/src/global_packages.dart
+++ b/sdk/lib/_internal/pub/lib/src/global_packages.dart
@@ -5,9 +5,10 @@
library pub.global_packages;
import 'dart:async';
+import 'dart:convert';
import 'dart:io';
-import 'package:path/path.dart' as path;
+import 'package:path/path.dart' as p;
import 'io.dart';
import 'lock_file.dart';
@@ -33,7 +34,7 @@ class GlobalPackages {
final SystemCache cache;
/// The directory where the lockfiles for activated packages are stored.
- String get _directory => path.join(cache.rootDir, "global_packages");
+ String get _directory => p.join(cache.rootDir, "global_packages");
/// The source that global packages can be activated from.
// TODO(rnystrom): Allow activating packages from other sources.
@@ -49,7 +50,7 @@ class GlobalPackages {
/// Finds the latest version of the hosted package with [name] that matches
/// [constraint] and makes it the active global version.
Future activate(String name, VersionConstraint constraint) {
- var lockFilePath = path.join(_directory, name + ".lock");
+ var lockFilePath = p.join(_directory, name + ".lock");
// See if we already have it activated.
var lockFile;
@@ -106,6 +107,22 @@ class GlobalPackages {
});
}
+ /// Deactivates a previously-activated package named [name] or fails with
+ /// an error if [name] is not an active package.
+ void deactivate(String name) {
+ // See if we already have it activated.
+ try {
+ var lockFilePath = p.join(_directory, name + ".lock");
nweiz 2014/06/30 20:59:04 Nit: I'd write "$name.lock"
Bob Nystrom 2014/06/30 21:35:52 Done.
+ var lockFile = new LockFile.load(lockFilePath, cache.sources);
+ var version = lockFile.packages[name].version;
+
+ deleteEntry(lockFilePath);
+ log.message("Deactivated package ${log.bold(name)} $version.");
+ } on IOException catch (error) {
+ dataError("No active package ${log.bold(name)}.");
+ }
+ }
+
/// Picks the best version of [package] to activate that meets [constraint].
///
/// If [version] is not `null`, this tries to maintain that version if
@@ -123,6 +140,7 @@ class GlobalPackages {
if (versions.isEmpty) {
// TODO(rnystrom): Show most recent unmatching version?
+ dataError("Package $package has no versions that match $constraint.");
nweiz 2014/06/30 20:59:04 Why is this line added? If it's here, shouldn't th
Bob Nystrom 2014/06/30 21:35:52 Oops. Merge mistake. Fixed.
dataError("Package ${log.bold(package)} has no versions that match "
"$constraint.");
}

Powered by Google App Engine
This is Rietveld 408576698