Skip to content

Commit

Permalink
[cli] console command
Browse files Browse the repository at this point in the history
start apicast console and optionally execute a file
  • Loading branch information
mikz committed Aug 23, 2018
1 parent fb579bc commit 7c96dc9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions gateway/src/apicast/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ end
_M.commands = load_commands({
'start',
'generate',
'console',
}, parser)

function mt.__call(self, arg)
Expand Down
31 changes: 31 additions & 0 deletions gateway/src/apicast/cli/command/console.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local setmetatable = setmetatable

local _M = { }
local mt = { __index = _M }

local function configure(cmd)
cmd:argument('file', 'file to execute'):args("?")
return cmd
end

function _M.new(parser)
local cmd = configure(parser:command('console', 'Start console'))

return setmetatable({ parser = parser, cmd = cmd }, mt)
end

function mt:__call(options)
local repl = require('resty.repl')

_G.repl = repl.start

function _G.reload() package.loaded = {} end

if options.file then
dofile(options.file)
end

repl.start()
end

return setmetatable(_M, mt)

0 comments on commit 7c96dc9

Please sign in to comment.