diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 5b28c8e93..9f10a76d0 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -2313,15 +2313,15 @@ class RemoveCommand : FetchRemoveCommand { if (!m_version.empty) { // remove then --version removed enforceUsage(!package_id.canFindVersionSplitter, "Double version spec not allowed."); logWarn("The '--version' parameter was deprecated, use %s@%s. Please update your scripts.", package_id, m_version); - dub.remove(package_id, m_version, location); + dub.remove(PackageName(package_id), m_version, location); } else { const parts = UserPackageDesc.fromString(package_id); const explicit = package_id.canFindVersionSplitter; if (m_nonInteractive || explicit || parts.range != VersionRange.Any) { const str = parts.range.matchesAny() ? "*" : parts.range.toString(); - dub.remove(parts.name, str, location); + dub.remove(PackageName(parts.name), str, location); } else { - dub.remove(package_id, location, &resolveVersion); + dub.remove(PackageName(package_id), location, &resolveVersion); } } return 0; diff --git a/source/dub/dub.d b/source/dub/dub.d index 1a85ffd24..24678e2a8 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -1071,15 +1071,17 @@ class Dub { is set to `RemoveVersionWildcard`. Params: - package_id = Name of the package to be removed + name = Name of the package to be removed location = Specifies the location to look for the given package name/version. resolve_version = Callback to select package version. */ - void remove(string package_id, PlacementLocation location, - scope size_t delegate(in Package[] packages) resolve_version) + void remove(in PackageName name, PlacementLocation location, + scope size_t delegate(in Package[] packages) resolve_version) { - enforce(!package_id.empty); + enforce(name.main.toString().length); + enforce(!name.sub.length, "Cannot remove subpackage %s, remove %s instead" + .format(name, name.main)); if (location == PlacementLocation.local) { logInfo("To remove a locally placed package, make sure you don't have any data" ~ "\nleft in it's directory and then simply remove the whole directory."); @@ -1089,16 +1091,13 @@ class Dub { Package[] packages; // Retrieve packages to be removed. - foreach(pack; m_packageManager.getPackageIterator(package_id)) + foreach(pack; m_packageManager.getPackageIterator(name.toString())) if (m_packageManager.isManagedPackage(pack)) packages ~= pack; // Check validity of packages to be removed. - if(packages.empty) { - throw new Exception("Cannot find package to remove. (" - ~ "id: '" ~ package_id ~ "', location: '" ~ to!string(location) ~ "'" - ~ ")"); - } + enforce(!packages.empty, "Cannot find package '%s' to remove at %s location" + .format(name, location.toString())); // Sort package list in ascending version order packages.sort!((a, b) => a.version_ < b.version_); @@ -1114,12 +1113,19 @@ class Dub { try { remove(pack); } catch (Exception e) { - logError("Failed to remove %s %s: %s", package_id, pack, e.msg); + logError("Failed to remove %s %s: %s", name, pack, e.msg); logInfo("Continuing with other packages (if any)."); } } } + deprecated("Use `remove(PackageName, PlacementLocation, delegate)`") + void remove(string name, PlacementLocation location, + scope size_t delegate(in Package[] packages) resolve_version) + { + this.remove(PackageName(name), location, resolve_version); + } + /// Compatibility overload. Use the version without a `force_remove` argument instead. deprecated("Use the overload without the 3rd argument (`force_remove`) instead") void remove(string package_id, PlacementLocation location, bool force_remove, @@ -1131,7 +1137,7 @@ class Dub { /** Removes a specific version of a package. Params: - package_id = Name of the package to be removed + name = Name of the package to be removed version_ = Identifying a version or a wild card. If an empty string is passed, the package will be removed from the location, if there is only one version retrieved. This will throw an @@ -1139,9 +1145,9 @@ class Dub { location = Specifies the location to look for the given package name/version. */ - void remove(string package_id, string version_, PlacementLocation location) + void remove(in PackageName name, string version_, PlacementLocation location) { - remove(package_id, location, (in packages) { + remove(name, location, (in packages) { if (version_ == RemoveVersionWildcard || version_.empty) return packages.length; @@ -1149,12 +1155,17 @@ class Dub { if (p.version_ == Version(version_)) return i; } - throw new Exception("Cannot find package to remove. (" - ~ "id: '" ~ package_id ~ "', version: '" ~ version_ ~ "', location: '" ~ to!string(location) ~ "'" - ~ ")"); + throw new Exception("Cannot find package '%s@%s' to remove at %s location" + .format(name, version_, location.toString())); }); } + deprecated("Use `remove(PackageName, string, PlacementLocation)`") + void remove(string name, string version_, PlacementLocation location) + { + this.remove(PackageName(name), version_, location); + } + /// Compatibility overload. Use the version without a `force_remove` argument instead. deprecated("Use the overload without force_remove instead") void remove(string package_id, string version_, PlacementLocation location, bool force_remove) diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 549dae491..9ec7d4a82 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -885,6 +885,7 @@ symlink_exit: { logDebug("Remove %s, version %s, path '%s'", pack.name, pack.version_, pack.path); enforce(!pack.path.empty, "Cannot remove package "~pack.name~" without a path."); + enforce(pack.parentPackage is null, "Cannot remove subpackage %s".format(pack.name)); // remove package from repositories' list bool found = false;