libs/lpk: Updated CLI

This commit is contained in:
Steven Barth 2008-07-29 16:24:24 +00:00
parent b93f0acce6
commit 41eceab4c4
3 changed files with 45 additions and 28 deletions

View file

@ -6,12 +6,11 @@ __appname__ = "LuCI »lpk« Package Manager"
__version__ = "0.1" __version__ = "0.1"
__authors__ = "Steven Barth, Jo-Philipp Wich" __authors__ = "Steven Barth, Jo-Philipp Wich"
__cpyrght__ = string.format("Copyright (c) 2008 %s", __authors__) __cpyrght__ = string.format("Copyright (c) 2008 %s", __authors__)
__welcome__ = string.format("%s v%s\n%s",
__appname__, __version__, __cpyrght__)
options, arguments = luci.lpk.util.getopt(arg) options, arguments = luci.lpk.util.getopt(arg)
config = luci.util.dtable() config = luci.util.dtable()
machine = luci.lpk.core.Machine()
local cfgdump = loadfile("/etc/lpk.conf") local cfgdump = loadfile("/etc/lpk.conf")
if cfgdump then if cfgdump then
@ -20,23 +19,22 @@ if cfgdump then
end end
if #arguments < 1 then if #arguments < 1 then
print(__welcome__) luci.lpk.util.splash()
print([[
Usage:
lpk [options] <command> [arguments]
lpk [options] install|remove pkg1 [pkg2] [...] [pkgn]
Commands:
install - Install packages
remove - Remove packages
purge - Remove packages and their configuration files
Options:
--force-depends - Ignore unresolvable dependencies
]])
else else
-- Start machine local task, error = machine:task(table.remove(arguments, 1),
unpack(arguments))
if task then
local stat, error = task:perform()
if not stat then
luci.util.perror(error or task.register.errstr or "Unknown Error")
os.exit(task.register.error or 1)
end
else
luci.util.perror(error .. "\n")
luci.lpk.util.splash()
os.exit(1)
end
end end

View file

@ -68,9 +68,12 @@ function Task.perform(self)
stat, err = self:rollback() stat, err = self:rollback()
until not stat until not stat
assert(not err, "Machine broken!") if err then
self.register.errstr = err
self.register.error = 2
end
return false, self.register.error return false
end end
end end
@ -89,15 +92,11 @@ end
function Machine.task(self, name, ...) function Machine.task(self, name, ...)
local start = self:state(name) local start = self:state(name)
if not start or not start.entry then if type(start) ~= "table" or not start.entry then
error("No such command: " .. name) return false, "No such command: " .. name
end end
local register = {} local register = {}
if start:entry(register) then return start:entry(register) and Task(self, register, start)
return Task(self, register, start)
else
return nil, register.error
end
end end

View file

@ -36,4 +36,24 @@ function getopt( arg, options )
end end
end end
return tab, args return tab, args
end
function splash()
require("luci.lpk")
luci.util.perror(string.format("%s v%s\n%s",
luci.lpk.__appname__, luci.lpk.__version__, luci.lpk.__cpyrght__))
luci.util.perror([[
Usage:
lpk [options] <command> [arguments]
lpk [options] install|remove pkg1 [pkg2] [...] [pkgn]
Commands:
install - Install packages
remove - Remove packages
purge - Remove packages and their configuration files
Options:
--force-depends - Ignore unresolvable dependencies
]])
end end