libs/lpk: Several fixes in CLI -> Machine bindings
This commit is contained in:
parent
41eceab4c4
commit
8dad54251a
5 changed files with 33 additions and 4 deletions
|
@ -31,7 +31,7 @@ else
|
|||
os.exit(task.register.error or 1)
|
||||
end
|
||||
else
|
||||
luci.util.perror(error .. "\n")
|
||||
luci.util.perror((error or "Unknown Error") .. "\n")
|
||||
luci.lpk.util.splash()
|
||||
os.exit(1)
|
||||
end
|
||||
|
|
|
@ -22,6 +22,10 @@ function Task.rollback(self)
|
|||
end
|
||||
|
||||
local state = table.remove(self.done)
|
||||
if not state.rollback then
|
||||
return true
|
||||
end
|
||||
|
||||
local ret, err = pcall(state.rollback, state, self.register)
|
||||
|
||||
if ret then
|
||||
|
@ -33,7 +37,7 @@ end
|
|||
|
||||
function Task.step(self)
|
||||
local state = table.remove(self.work)
|
||||
local ret, next = pcall(state.process, state, self.register)
|
||||
local ret, next = pcall(state.process, self.register)
|
||||
|
||||
if ret then
|
||||
if next then
|
||||
|
@ -42,7 +46,8 @@ function Task.step(self)
|
|||
table.insert(self.work, state)
|
||||
table.insert(self.work, nstate)
|
||||
else
|
||||
self.register.error = "Unknown state: " .. next
|
||||
self.register.error = 2
|
||||
self.register.errstr = "Unknown state: " .. next
|
||||
return false
|
||||
end
|
||||
else
|
||||
|
@ -98,5 +103,5 @@ function Machine.task(self, name, ...)
|
|||
|
||||
local register = {}
|
||||
|
||||
return start:entry(register) and Task(self, register, start)
|
||||
return start.entry(register, ...) and Task(self, register, start)
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
module("luci.lpk.core.download", package.seeall)
|
|
@ -0,0 +1,16 @@
|
|||
module("luci.lpk.core.install", package.seeall)
|
||||
|
||||
function entry(register, ...)
|
||||
print("Requested install of " .. table.concat(arg, ", "))
|
||||
return true
|
||||
end
|
||||
|
||||
function process(register)
|
||||
register.sometext = "Test"
|
||||
if not register.retreived then
|
||||
print("Step down to retreive")
|
||||
return "retreive"
|
||||
else
|
||||
print("Coming up again")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
module("luci.lpk.core.retreive", package.seeall)
|
||||
|
||||
function process(register)
|
||||
print "Now in retreive"
|
||||
print (register.sometext)
|
||||
register.retreived = true
|
||||
end
|
Loading…
Reference in a new issue