mirror of https://github.com/Hilbis/Hilbish
feat: extend hilbish.runner interface to allow multiple runners
parent
e3c25586e4
commit
dce49574e6
|
@ -8,6 +8,7 @@ require 'nature.commands'
|
|||
require 'nature.completions'
|
||||
require 'nature.opts'
|
||||
require 'nature.vim'
|
||||
require 'nature.runner'
|
||||
|
||||
local shlvl = tonumber(os.getenv 'SHLVL')
|
||||
if shlvl ~= nil then
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
local currentRunner = 'hybrid'
|
||||
local runnerHandler = {}
|
||||
local runners = {}
|
||||
|
||||
function runnerHandler.get(name)
|
||||
local r = runners[name]
|
||||
|
||||
if not r then
|
||||
error(string.format('runner %s does not exist', name))
|
||||
end
|
||||
|
||||
return r
|
||||
end
|
||||
|
||||
function runnerHandler.add(name, runner)
|
||||
if type(name) ~= 'string' then
|
||||
error 'expected runner name to be a table'
|
||||
end
|
||||
|
||||
if type(runner) ~= 'table' then
|
||||
error 'expected runner to be a table'
|
||||
end
|
||||
|
||||
if runners[name] then
|
||||
error(string.format('runner %s already exists', name))
|
||||
end
|
||||
|
||||
runnerHandler.set(name, runner)
|
||||
end
|
||||
|
||||
function runnerHandler.set(name, runner)
|
||||
if not runner.run or type(runner.run) ~= 'function' then
|
||||
error 'run function in runner missing'
|
||||
end
|
||||
|
||||
runners[name] = runner
|
||||
end
|
||||
|
||||
function runnerHandler.exec(cmd, runnerName)
|
||||
if not runnerName then runnerName = currentRunner end
|
||||
|
||||
local r = runnerHandler.get(runnerName)
|
||||
|
||||
return r.run(cmd)
|
||||
end
|
||||
|
||||
function runnerHandler.setCurrent(name)
|
||||
local r = runnerHandler.get(name)
|
||||
currentRunner = name
|
||||
|
||||
hilbish.runner.setMode(r.run)
|
||||
end
|
||||
|
||||
-- add functions to hilbish.runner
|
||||
for k, v in ipairs(runnerHandler) do hilbish.runner[k] = v end
|
||||
|
Loading…
Reference in New Issue