From 5b547e5ba98083d457d69503adb51b4d0ee27c7f Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 14 Mar 2023 17:32:19 -0400 Subject: Added in replaces to the SPEC, and to lpm. --- SPEC.md | 2 ++ src/lpm.lua | 20 ++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/SPEC.md b/SPEC.md index 8a2964b..afa8008 100644 --- a/SPEC.md +++ b/SPEC.md @@ -52,6 +52,8 @@ Fields that are required are bolded. * `description`: An optional english-language description of the addon. * `provides`: An optional array of strings that are a shorthand of functionality this addon provides. Can be used as a dependency. +* `replaces`: An optional array of ids that this plugin explicitly replaces. Will always + prefer this plugin in place of those plugins, so long as version requirements are met. * `remote`: Optional. Specifies an https git link wheree this addon is located. If present, denotes a **stub**. * `dependencies`: Optionally a hash of dependencies required, or optional diff --git a/src/lpm.lua b/src/lpm.lua index 3f1e4df..5004ead 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -1328,20 +1328,17 @@ function Bottle:get_addon(id, version, filter) local wildcard = id:find("%*$") filter = filter or {} for i,addon in ipairs(self:all_addons()) do - if not version and addon.provides then - for k, provides in ipairs(addon.provides) do - if provides == id then - table.insert(candidates, addon) - end - end - end - if (addon.id == id or (wildcard and addon.id:find("^" .. id:sub(1, #id - 1)))) and match_version(addon.version, version) then - if (not filter.mod_version or not addon.mod_version or compatible_modversion(filter.mod_version, addon.mod_version)) then + if (common.first(addon.replaces or {}, function(replaces) return replaces == id end) or + common.first(addon.provides or {}, function(provides) return provides == id end) or + (addon.id == id or (wildcard and addon.id:find("^" .. id:sub(1, #id - 1))))) and + match_version(addon.version, version) and (not filter.mod_version or not addon.mod_version or compatible_modversion(filter.mod_version, addon.mod_version)) + then table.insert(candidates, addon) - end end end - return table.unpack(common.sort(common.uniq(candidates), function (a,b) return a.version < b.version end)) + return table.unpack(common.sort(common.uniq(candidates), function (a,b) + return (a.replaces == id and b.replaces ~= id) or (a.version < b.version) + end)) end local function get_repository(url) @@ -2117,7 +2114,6 @@ not commonly used publically. end if not system_bottle then system_bottle = Bottle.new(nil, nil, true) end end, error_handler) - if ARGS[2] ~= '-' then engage_locks(function() run_command(ARGS) -- cgit v1.2.3