generated from version-fox/vfox-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathavailable.lua
47 lines (42 loc) · 1.55 KB
/
available.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local foojay = require("foojay")
local distribution_version_parser = require("distribution_version")
--- Return all available versions provided by this plugin
--- @param ctx table Empty table used as context, for future extension
--- @return table Descriptions of available versions and accompanying tool descriptions
function PLUGIN:Available(ctx)
local query = ctx.args[1] or "open"
local jdks = {}
if query == "all" then
for _, distribution in ipairs(distribution_version_parser.distributions) do
local tempJdks = foojay.fetchtJdkList(distribution.name, "")
for _, jdk in ipairs(tempJdks) do
jdk.short = distribution.short_name
table.insert(jdks, jdk)
end
end
else
jdks = foojay.fetchtJdkList(distribution_version_parser.parse_distribution(query).name or error("Unsupported distribution: " .. query), "")
end
local result = {}
local seen = {}
for _, jdk in ipairs(jdks) do
local v = jdk.java_version
local short = jdk.short
if query == "all" then
v = v .. "-" .. short
elseif query == "open" then
v = v
else
v = v .. "-" .. distribution_version_parser.parse_distribution(query).short_name
end
if not seen[v] then
seen[v] = true
-- check if version exists
table.insert(result, {
version = v,
note = jdk.term_of_support == "lts" and "LTS" or ""
})
end
end
return result
end