package manager install/uninstall directives

This commit is contained in:
kepler155c@gmail.com 2019-11-09 21:15:07 -07:00
parent 57ea46dde7
commit 9ef4d9ef64
2 changed files with 27 additions and 1 deletions

View File

@ -9,6 +9,12 @@ local term = _G.term
local args = { ... }
local action = table.remove(args, 1)
local function makeSandbox()
local sandbox = setmetatable(Util.shallowCopy(_ENV), { __index = _G })
_G.requireInjector(sandbox)
return sandbox
end
local function Syntax(msg)
_G.printError(msg)
print('\nSyntax: Package list | install [name] ... | update [name] | uninstall [name]')
@ -71,6 +77,17 @@ local function install(name, isUpdate, ignoreDeps)
end
showProgress()
end)
if not isUpdate then
if manifest.install then
local s, m = pcall(function()
load(manifest.install, 'install', nil, makeSandbox())
end)
if not s and m then
_G.printError(m)
end
end
end
end
if action == 'list' then
@ -121,6 +138,15 @@ if action == 'uninstall' then
if not Packages:isInstalled(name) then
error('Package is not installed')
end
local manifest = Packages:getManifest(name)
if manifest.uninstall then
local s, m = pcall(function()
load(manifest.uninstall, 'uninstall', nil, makeSandbox())
end)
if not s and m then
_G.printError(m)
end
end
local packageDir = fs.combine('packages', name)
fs.delete(packageDir)
print('removed: ' .. packageDir)

View File

@ -44,7 +44,7 @@ function Alt.addChoice(key, value)
config.choices[key] = { }
end
if not Util.contains(config.choices[key], value) then
config.choices[key] = value
table.insert(config.choices[key], value)
Config.update('alternate', config)
end
end