diff options
| author | ruki <[email protected]> | 2024-11-27 00:43:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-11-27 00:43:23 +0800 |
| commit | c4d249edd48667214a08900e5e9f6b2a7222552a (patch) | |
| tree | 07fbe8859b039ee077689cca4444730e80a2fb2b | |
| parent | 3276686e4d2356dab029d94ada8f780e0702889a (diff) | |
add unknown package tips
| -rw-r--r-- | xmake/modules/private/action/require/impl/install_packages.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/quick_search/cache.lua | 2 |
2 files changed, 26 insertions, 2 deletions
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index ba1ccdbd8..005ca0fe5 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -29,6 +29,7 @@ import("utils.progress") import("net.fasturl") import("private.action.require.impl.package") import("private.action.require.impl.lock_packages") +import("private.action.require.impl.search_packages") import("private.action.require.impl.register_packages") import("private.action.require.impl.actions.check", {alias = "action_check"}) import("private.action.require.impl.actions.install", {alias = "action_install"}) @@ -681,6 +682,24 @@ function _get_package_installdeps(packages) return installdeps end +-- get possible package +function _get_possible_package(packagename) + local packages_possible = search_packages("*", {description = false}) + if packages_possible then + packages_possible = packages_possible["*"] + end + local result + local distance_min + for name, info in pairs(packages_possible) do + local distance = packagename:levenshtein(info.name) + if distance_min == nil or distance < distance_min and distance < 5 then + distance_min = distance + result = info + end + end + return result +end + -- install packages function _install_packages(requires, opt) opt = opt or {} @@ -745,7 +764,12 @@ function _install_packages(requires, opt) if #packages_unknown > 0 then cprint("${bright color.warning}note: ${clear}the following packages were not found in any repository (check if they are spelled correctly):") for _, instance in ipairs(packages_unknown) do - print(" -> %s", instance:displayname()) + local tips + local possible_package = _get_possible_package(instance:name()) + if possible_package then + tips = string.format(", maybe ${bright}%s %s${clear} in %s", possible_package.name, possible_package.version, possible_package.reponame) + end + cprint(" -> %s%s", instance:displayname(), tips or "") end has_errors = true end diff --git a/xmake/modules/private/xrepo/quick_search/cache.lua b/xmake/modules/private/xrepo/quick_search/cache.lua index 9ba142076..ceefad3fc 100644 --- a/xmake/modules/private/xrepo/quick_search/cache.lua +++ b/xmake/modules/private/xrepo/quick_search/cache.lua @@ -88,7 +88,7 @@ function find(name, opt) if opt.prefix then found = packagename:startswith(name) else - found = packagename:find(name) + found = packagename:find(path.pattern(name)) end if not found and opt.description and packagedata.description and packagedata.description:find(name) then found = true |
