Made installing virtual packages actually work
This commit is contained in:
+16
-13
@@ -94,7 +94,7 @@ end
|
|||||||
local packages = parsed.args
|
local packages = parsed.args
|
||||||
table.remove(packages, 1)
|
table.remove(packages, 1)
|
||||||
-- Remove the command from the actual package list
|
-- Remove the command from the actual package list
|
||||||
local result, data, failure
|
-- local result, data, failure
|
||||||
do
|
do
|
||||||
local function check(condition, message)
|
local function check(condition, message)
|
||||||
if not condition then
|
if not condition then
|
||||||
@@ -126,18 +126,18 @@ if not success then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getServersidePackageConfig(source)
|
local function getServersidePackageConfig(source, package)
|
||||||
local success, data = getFile(fs.concat(source, "/ag2.json"))
|
local success, data = getFile(fs.concat(source, "/ag2.json"))
|
||||||
if not success then
|
if not success then
|
||||||
return false, ("\27[91mFailed to get package config (ag2.json) of package '%s': " .. data):format(packages[i])
|
return false, ("\27[91mFailed to get package config (ag2.json) of package '%s': " .. data):format(package)
|
||||||
end
|
end
|
||||||
local success, packageConfig = pcall(function()
|
local success, packageConfig = pcall(function()
|
||||||
return json.decode(data)
|
return json.decode(data)
|
||||||
end)
|
end)
|
||||||
if not success then
|
if not success then
|
||||||
return false, ("\27[91mFailed to parse package config (ag2.json) of package '%s': " .. packageConfig):format(packages[i])
|
return false, ("\27[91mFailed to parse package config (ag2.json) of package '%s': " .. packageConfig):format(package)
|
||||||
end
|
end
|
||||||
if not packageConfig[packages[i]] then
|
if not packageConfig[package] then
|
||||||
return false, ("\27[91mRepository package config (ag2.json) does not contain package '%s'."):format(package)
|
return false, ("\27[91mRepository package config (ag2.json) does not contain package '%s'."):format(package)
|
||||||
end
|
end
|
||||||
return packageConfig[package]
|
return packageConfig[package]
|
||||||
@@ -152,14 +152,14 @@ if command == "install" then
|
|||||||
if parsed.s or parsed.source then
|
if parsed.s or parsed.source then
|
||||||
source = parsed.s or parsed.source
|
source = parsed.s or parsed.source
|
||||||
else
|
else
|
||||||
source = registry[package]
|
source = registry[packages[i]]
|
||||||
end
|
end
|
||||||
if not source then
|
if not source then
|
||||||
print("\27[91mCould not find package in registry and no source provided: " .. packages[i])
|
print("\27[91mCould not find package in registry and no source provided: " .. packages[i])
|
||||||
failure = true
|
failure = true
|
||||||
goto SKIP
|
goto SKIP
|
||||||
end
|
end
|
||||||
local packageConfig, errorMessage = getServersidePackageConfig(source)
|
local packageConfig, errorMessage = getServersidePackageConfig(source, packages[i])
|
||||||
if not packageConfig then
|
if not packageConfig then
|
||||||
failure = true
|
failure = true
|
||||||
print(errorMessage)
|
print(errorMessage)
|
||||||
@@ -171,7 +171,7 @@ if command == "install" then
|
|||||||
table.insert(packages, package)
|
table.insert(packages, package)
|
||||||
end
|
end
|
||||||
elseif packageConfig.type == "virtual-package" then
|
elseif packageConfig.type == "virtual-package" then
|
||||||
print(("Installing virtual package %s"):format(package))
|
print(("Installing virtual package %s"):format(packages[i]))
|
||||||
local pkgAskText = ("Select a package by typing in its number: 1) %s"):format(packageConfig.packages[1])
|
local pkgAskText = ("Select a package by typing in its number: 1) %s"):format(packageConfig.packages[1])
|
||||||
-- This is all a silly workaround to place commas correctly
|
-- This is all a silly workaround to place commas correctly
|
||||||
for i = 2, #packageConfig.packages do
|
for i = 2, #packageConfig.packages do
|
||||||
@@ -182,10 +182,13 @@ if command == "install" then
|
|||||||
local packageSel = terminal.read()
|
local packageSel = terminal.read()
|
||||||
if not tonumber(packageSel) or tonumber(packageSel) % 1 ~= 0 then
|
if not tonumber(packageSel) or tonumber(packageSel) % 1 ~= 0 then
|
||||||
-- Is there really no better way to check for an int..?
|
-- Is there really no better way to check for an int..?
|
||||||
print("\27[91mNon-integer received - try again")
|
print("\27[93mNon-integer received - try again\27[0m")
|
||||||
goto RETRY
|
goto RETRY
|
||||||
end
|
end
|
||||||
packages[i] = packageConfig.packages[packageSel]
|
if tonumber(packageSel) < 1 or tonumber(packageSel) > #packageConfig.packages then
|
||||||
|
print("\27[93mInteger out of range - try again\27[0m")
|
||||||
|
end
|
||||||
|
packages[i] = packageConfig.packages[tonumber(packageSel)]
|
||||||
i = i - 1
|
i = i - 1
|
||||||
goto SKIP
|
goto SKIP
|
||||||
end
|
end
|
||||||
@@ -215,7 +218,7 @@ elseif command == "remove" then
|
|||||||
source = registry[package]
|
source = registry[package]
|
||||||
end
|
end
|
||||||
if source then
|
if source then
|
||||||
local packageConfig = getServersidePackageConfig(source)
|
local packageConfig = getServersidePackageConfig(source, packages[i])
|
||||||
if packageConfig then
|
if packageConfig then
|
||||||
if packageConfig.type == "virtual-package" or packageConfig.type == "group" then
|
if packageConfig.type == "virtual-package" or packageConfig.type == "group" then
|
||||||
table.remove(packages, i)
|
table.remove(packages, i)
|
||||||
@@ -235,10 +238,10 @@ elseif command == "remove" then
|
|||||||
|
|
||||||
-- I was originally gonna add this in the dependency cascade section, but realized it could shorten the normal dependency check code a bit
|
-- I was originally gonna add this in the dependency cascade section, but realized it could shorten the normal dependency check code a bit
|
||||||
local dependencyList = {}
|
local dependencyList = {}
|
||||||
for _, packageConfig in fs.list("/ag2/pkg/") do
|
for _, packageConfig in ipairs(fs.list("/ag2/pkg/")) do
|
||||||
local package = packageConfig:sub(1, -6)
|
local package = packageConfig:sub(1, -6)
|
||||||
-- I'm not adding error handling here because if this fails then fuck you for touching the files by hand and good luck figuring this shit out
|
-- I'm not adding error handling here because if this fails then fuck you for touching the files by hand and good luck figuring this shit out
|
||||||
local _, data = getFile(("/ag2/pkg/%s.json"):format(packages[i]))
|
local _, data = getFile(("/ag2/pkg/%s.json"):format(package))
|
||||||
data = json.decode(data)
|
data = json.decode(data)
|
||||||
dependencyList[package] = data.dependencies
|
dependencyList[package] = data.dependencies
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user