Skip to content

Commit

Permalink
Try a more structured interface
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Oct 6, 2023
1 parent 2cf8809 commit 18e7561
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions shells/JsonShell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,39 @@ Json.my_name = "json"
Json.myType = Json.my_name
Json.js = ""

function Json.initialize(self)
-- Empty the json script so that it can be used in individual --
self.js = json.encode({alias={}, shellFunc={}, env={}, unset={}})
end

function Json.alias(self, k, v)
-- do nothing: everything is handled in expand
local tbl = js.decode(self.js)
tbl["alias"][k] = v
self.js = js.encode(tbl)
end

function Json.shellFunc(self, k, v)
-- do nothing: everything is handled in expand
local tbl = js.decode(self.js)
tbl["shellFunc"][k] = v
self.js = js.encode(tbl)
end

function Json.expandVar(self, k, v, vType)
-- do nothing: everything is handled in expand
local tbl = js.decode(self.js)
tbl["env"][k] = v
self.js = js.encode(tbl)
end

function Json.unset(self, k, vType)
-- do nothing: everything is handled in expand
local tbl = js.decode(self.js)
tbl["unset"][#tbl["unset"]+1] = k
self.js = js.encode(tbl)
end

function Json.echo(self,...)
self:_echo(...)
end

function Json.expand(self, tbl)
self.js = js.encode(tbl)
BaseShell.expand(self, tbl)
end

function Json.report_failure(self)
local js_txt = js.encode({_mlstatus=false})
stdout:write(js_txt)
Expand All @@ -85,7 +93,7 @@ function Json.report_success(self)
local report = js.decode(self.js)
report["_mlstatus"] = true
stdout:write(js.encode(report))
dbg.print{ self.js}
dbg.print{self.js}
end

return Json

0 comments on commit 18e7561

Please sign in to comment.