diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 7c2a578..525e682 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -19,7 +19,7 @@ import dub.packagesupplier; import dub.platform : determineCompiler; import dub.project; -import dub.internal.utils : getDUBVersion; +import dub.internal.utils : getDUBVersion, getClosestMatch; import std.algorithm; import std.array; @@ -372,7 +372,14 @@ m_defaultConfig = null; enforce (loadSpecificPackage(dub, package_name), "Failed to load package."); - enforce(m_buildConfig.length == 0 || dub.configurations.canFind(m_buildConfig), "Unknown build configuration: "~m_buildConfig); + if (m_buildConfig.length != 0 && !dub.configurations.canFind(m_buildConfig)) + { + string msg = "Unknown build configuration: "~m_buildConfig; + enum distance = 3; + if (auto match = dub.configurations.getClosestMatch(m_buildConfig, distance)) + msg ~= ". Did you mean '" ~ match ~ "'?"; + enforce(0, msg); + } if (m_buildType.length == 0) { if (environment.get("DFLAGS")) m_buildType = "$DFLAGS"; diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index e402ded..65273a5 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -1,6 +1,6 @@ /** ... - + Copyright: © 2012 Matthias Dondorff License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Matthias Dondorff @@ -208,4 +208,20 @@ default: return false; } return true; -} \ No newline at end of file +} + +/** + Get the closest match of $(D input) in the $(D array), where $(D distance) + is the maximum levenshtein distance allowed between the compared strings. + Returns $(D null) if no closest match is found. +*/ +string getClosestMatch(string[] array, string input, size_t distance) +{ + import std.algorithm : countUntil, map, levenshteinDistance; + import std.uni : toUpper; + + auto distMap = array.map!(elem => + levenshteinDistance!((a, b) => toUpper(a) == toUpper(b))(elem, input)); + auto idx = distMap.countUntil!(a => a <= distance); + return (idx == -1) ? null : array[idx]; +}