mirror of
https://github.com/kepler155c/opus
synced 2024-12-31 19:00:27 +00:00
package manager install/uninstall directives
This commit is contained in:
parent
57ea46dde7
commit
9ef4d9ef64
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user