aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2023-09-15 11:44:23 -0400
committerAdam Harrison <adamdharrison@gmail.com>2023-09-15 11:44:23 -0400
commit9844d754dbfde4936f1bb1348c1180908f5c8c46 (patch)
tree45d871aa54c31f25bc9120d50a6444cf636635c1
parent4129734c260c3e3a6091f515ddf0fc1ac2751b80 (diff)
downloadlite-xl-plugin-manager-9844d754dbfde4936f1bb1348c1180908f5c8c46.tar.gz
lite-xl-plugin-manager-9844d754dbfde4936f1bb1348c1180908f5c8c46.zip
Made desribe more modern.
-rw-r--r--src/lpm.lua116
1 files changed, 59 insertions, 57 deletions
diff --git a/src/lpm.lua b/src/lpm.lua
index 07d9c23..fc33eb9 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -1740,60 +1740,11 @@ local function lpm_install(type, ...)
end
-local function lpm_unstub(type, ...)
- local addons = {}
- for i, identifier in ipairs({ ... }) do
- if not identifier then error('unrecognized identifier ' .. identifier) end
- if is_argument_repo(identifier) then
- table.insert(repositories, 1, Repository.url(identifier):add(AUTO_PULL_REMOTES))
- else
- local potential_addons = { system_bottle:get_addon(identifier, nil, { mod_version = system_bottle.lite_xl.mod_version }) }
- addons = common.grep(potential_addons, function(e) return e:is_stub() end)
- if #addons == 0 and #potential_addons == 0 then error("can't find " .. (type or "addon") .. " " .. identifier .. " mod-version: " .. (system_bottle.lite_xl.mod_version or 'any')) end
- if #addons == 0 then
- log_warning((potential_addons[1].type or "addon") .. " " .. identifier .. " already unstubbed")
- end
- end
- end
- common.each(addons, function(e) e:unstub() end)
-end
-
-
-local function lpm_addon_uninstall(type, ...)
- for i, id in ipairs({ ... }) do
- local addons = { system_bottle:get_addon(id) }
- if #addons == 0 then error("can't find addon " .. id) end
- local installed_addons = common.grep(addons, function(e) return e:is_installed(system_bottle) and not e:is_core(system_bottle) end)
- if #installed_addons == 0 then error("addon " .. id .. " not installed") end
- for i, addon in ipairs(installed_addons) do
- addon:uninstall(system_bottle)
- settings.installed = common.grep(settings.installed, function(e) return e ~= addon.id end)
- end
- end
- lpm_settings_save()
-end
-
-local function lpm_addon_reinstall(type, ...) for i, id in ipairs({ ... }) do pcall(lpm_addon_uninstall, type, id) end lpm_install(type, ...) end
-
-local function lpm_repo_list()
- if JSON then
- io.stdout:write(json.encode({ repositories = common.map(repositories, function(repo) return { remote = repo.remote, commit = repo.commit, branch = repo.branch, path = repo.local_path, remotes = common.map(repo.remotes or {}, function(r) return r:url() end) } end) }) .. "\n")
- else
- for i, repository in ipairs(repositories) do
- local _, remotes = repository:parse_manifest()
- if i ~= 0 then print("---------------------------") end
- if not repository:is_local() then print("Remote : " .. repository:url()) end
- print("Path : " .. repository.local_path)
- print("Remotes: " .. json.encode(common.map(repository.remotes or {}, function(r) return r:url() end)))
- end
- end
-end
-
-local function lpm_addon_list(type, id, filters)
+local function print_addon_info(addons, filters)
local max_id = 4
local plural = (type or "addon") .. "s"
local result = { [plural] = { } }
- for j,addon in ipairs(common.grep(system_bottle:all_addons(), function(p) return (not type or p.type == type) and (not id or p.id:find(id)) end)) do
+ for j,addon in ipairs(addons) do
max_id = math.max(max_id, #addon.id)
local repo = addon.repository
local hash = {
@@ -1812,7 +1763,7 @@ local function lpm_addon_list(type, id, filters)
repository = repo and repo:url(),
path = addon:get_path(system_bottle)
}
- if addon_matches_filter(hash, filters) then table.insert(result[plural], hash) end
+ if addon_matches_filter(hash, filters or {}) then table.insert(result[plural], hash) end
end
if JSON then
io.stdout:write(json.encode(result) .. "\n")
@@ -1845,13 +1796,64 @@ local function lpm_addon_list(type, id, filters)
end
end
-local function lpm_describe()
- for i,v in ipairs(repositories) do
- if #common.grep(DEFAULT_REPOS, function(r) return r:url() == v:url() end) == 0 then
- io.stdout:write("lpm add " .. v:url() .. " && ")
+
+local function lpm_unstub(type, ...)
+ local addons = {}
+ for i, identifier in ipairs({ ... }) do
+ if not identifier then error('unrecognized identifier ' .. identifier) end
+ if is_argument_repo(identifier) then
+ table.insert(repositories, 1, Repository.url(identifier):add(AUTO_PULL_REMOTES))
+ else
+ local potential_addons = { system_bottle:get_addon(identifier, nil, { mod_version = system_bottle.lite_xl.mod_version }) }
+ addons = common.grep(potential_addons, function(e) return e:is_stub() end)
+ if #addons == 0 and #potential_addons == 0 then error("can't find " .. (type or "addon") .. " " .. identifier .. " mod-version: " .. (system_bottle.lite_xl.mod_version or 'any')) end
+ if #addons == 0 then
+ log_warning((potential_addons[1].type or "addon") .. " " .. identifier .. " already unstubbed")
+ end
+ end
+ end
+ common.each(addons, function(e) e:unstub() end)
+ print_addon_info(addons)
+end
+
+
+local function lpm_addon_uninstall(type, ...)
+ for i, id in ipairs({ ... }) do
+ local addons = { system_bottle:get_addon(id) }
+ if #addons == 0 then error("can't find addon " .. id) end
+ local installed_addons = common.grep(addons, function(e) return e:is_installed(system_bottle) and not e:is_core(system_bottle) end)
+ if #installed_addons == 0 then error("addon " .. id .. " not installed") end
+ for i, addon in ipairs(installed_addons) do
+ addon:uninstall(system_bottle)
+ settings.installed = common.grep(settings.installed, function(e) return e ~= addon.id end)
+ end
+ end
+ lpm_settings_save()
+end
+
+local function lpm_addon_reinstall(type, ...) for i, id in ipairs({ ... }) do pcall(lpm_addon_uninstall, type, id) end lpm_install(type, ...) end
+
+local function lpm_repo_list()
+ if JSON then
+ io.stdout:write(json.encode({ repositories = common.map(repositories, function(repo) return { remote = repo.remote, commit = repo.commit, branch = repo.branch, path = repo.local_path, remotes = common.map(repo.remotes or {}, function(r) return r:url() end) } end) }) .. "\n")
+ else
+ for i, repository in ipairs(repositories) do
+ local _, remotes = repository:parse_manifest()
+ if i ~= 0 then print("---------------------------") end
+ if not repository:is_local() then print("Remote : " .. repository:url()) end
+ print("Path : " .. repository.local_path)
+ print("Remotes: " .. json.encode(common.map(repository.remotes or {}, function(r) return r:url() end)))
end
end
- print("lpm run " .. system_bottle.lite_xl.version .. " " .. common.join(" ", common.map(system_bottle:installed_addons(), function(p) return p.id .. ":" .. p.version end)))
+end
+
+local function lpm_addon_list(type, id, filters)
+ print_addon_info(common.grep(system_bottle:all_addons(), function(p) return (not type or p.type == type) and (not id or p.id:find(id)) end), filters)
+end
+
+local function lpm_describe()
+ local repo_urls = common.grep(common.map(repositories, function(e) return e:url() end), function(url) return #common.grep(DEFAULT_REPOS, function(r) return r:url() == url end) == 0 end)
+ print("lpm run " .. common.join(" ", { system_bottle.lite_xl.version, table.unpack(repo_urls) }) .. " " .. common.join(" ", common.map(system_bottle:installed_addons(), function(p) return p.id .. ":" .. p.version end)))
end
local function lpm_addon_upgrade()