summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-07-29 16:24:24 +0000
committerSteven Barth <steven@midlink.org>2008-07-29 16:24:24 +0000
commit41eceab4c413d331c14d3b3ba0e8bb355427f1f3 (patch)
treee00d44e7db05ff5be98d45767fc5ccf025efd212
parentb93f0acce6fe697ff2b7c5b571d4ccedaa244bcd (diff)
libs/lpk: Updated CLI
-rw-r--r--libs/lpk/luasrc/lpk.lua36
-rw-r--r--libs/lpk/luasrc/lpk/core.lua17
-rw-r--r--libs/lpk/luasrc/lpk/util.lua20
3 files changed, 45 insertions, 28 deletions
diff --git a/libs/lpk/luasrc/lpk.lua b/libs/lpk/luasrc/lpk.lua
index 56f62f0ca7..3b42a367ed 100644
--- a/libs/lpk/luasrc/lpk.lua
+++ b/libs/lpk/luasrc/lpk.lua
@@ -6,12 +6,11 @@ __appname__ = "LuCI »lpk« Package Manager"
__version__ = "0.1"
__authors__ = "Steven Barth, Jo-Philipp Wich"
__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)
-config = luci.util.dtable()
+config = luci.util.dtable()
+machine = luci.lpk.core.Machine()
local cfgdump = loadfile("/etc/lpk.conf")
if cfgdump then
@@ -20,23 +19,22 @@ if cfgdump then
end
if #arguments < 1 then
- print(__welcome__)
- 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
-]])
+ luci.lpk.util.splash()
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
diff --git a/libs/lpk/luasrc/lpk/core.lua b/libs/lpk/luasrc/lpk/core.lua
index 2ba5bfd250..bef5651c6a 100644
--- a/libs/lpk/luasrc/lpk/core.lua
+++ b/libs/lpk/luasrc/lpk/core.lua
@@ -68,9 +68,12 @@ function Task.perform(self)
stat, err = self:rollback()
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
@@ -89,15 +92,11 @@ end
function Machine.task(self, name, ...)
local start = self:state(name)
- if not start or not start.entry then
- error("No such command: " .. name)
+ if type(start) ~= "table" or not start.entry then
+ return false, "No such command: " .. name
end
local register = {}
- if start:entry(register) then
- return Task(self, register, start)
- else
- return nil, register.error
- end
+ return start:entry(register) and Task(self, register, start)
end
diff --git a/libs/lpk/luasrc/lpk/util.lua b/libs/lpk/luasrc/lpk/util.lua
index 50b33e105c..95bdb965f6 100644
--- a/libs/lpk/luasrc/lpk/util.lua
+++ b/libs/lpk/luasrc/lpk/util.lua
@@ -36,4 +36,24 @@ function getopt( arg, options )
end
end
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 \ No newline at end of file