diff --git a/gateway/src/apicast/cli.lua b/gateway/src/apicast/cli.lua index 7f5548be7..19b7bca3e 100644 --- a/gateway/src/apicast/cli.lua +++ b/gateway/src/apicast/cli.lua @@ -23,6 +23,7 @@ end _M.commands = load_commands({ 'start', 'generate', + 'console', }, parser) function mt.__call(self, arg) diff --git a/gateway/src/apicast/cli/command/console.lua b/gateway/src/apicast/cli/command/console.lua new file mode 100644 index 000000000..289184952 --- /dev/null +++ b/gateway/src/apicast/cli/command/console.lua @@ -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)