diff --git a/source/dub/dub.d b/source/dub/dub.d index 034f5726e..46060ac1f 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -616,7 +616,18 @@ class Dub { auto versionStrings = ps.getVersions(dep); depVers[dep] = versionStrings[$-1].toString; } catch(Exception e){ - logError("Error, no package %s found. Ignoring...", dep); + auto packages = ps.getPackageNames(); + string[][size_t] lds; //holds the levenshteinDistance from dep for each package + foreach(pack; packages){ + lds[dep.levenshteinDistance(pack)] ~= pack; + } + auto closestKey = lds.keys.sort.front; + if(closestKey <= 4){ + logError("Error, no package \"%s\" found. Did you mean %s?", dep, lds[closestKey]); + } else{ + logError("Error, no package \"%s\" found. Exiting...", dep); + } + return; } } } diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index 12e9b0404..c087713d1 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -41,6 +41,9 @@ interface PackageSupplier { /// perform cache operation void cacheOp(Path cacheDir, CacheOp op); + + /// get all package names for this supplier + string[] getPackageNames(); } /// operations on package supplier cache @@ -92,6 +95,10 @@ class FileSystemPackageSupplier : PackageSupplier { void cacheOp(Path cacheDir, CacheOp op) { } + string[] getPackageNames(){ + assert(false, "FileSystemPackageSupplier.getPackageNames, not implemented yet"); + } + private Path bestPackageFile(string packageId, Dependency dep, bool pre_release) { Path toPath(Version ver) { @@ -148,11 +155,23 @@ class RegistryPackageSupplier : PackageSupplier { download(url, path); } + Json getPackageDescription(string packageId, Dependency dep, bool pre_release) { return getBestPackage(packageId, dep, pre_release); } + string[] getPackageNames(){ + import std.array : replace; + auto url = m_registryUrl ~ Path(PackagesPath~"/index.json"); + Json data = (cast(string)download(url)).parseJsonString(); + string[] packages; + foreach(ele; data){ + packages ~= ele.toString().replace("\"", ""); + } + return packages; + } + void cacheOp(Path cacheDir, CacheOp op) { auto path = cacheDir ~ cacheFileName;