refactor: split Sloth subcommands in their own files
parent
ab361c86b4
commit
29e8841a3d
|
|
@ -81,7 +81,12 @@
|
|||
buildPhase = ''
|
||||
dir=lua/sloth-flake
|
||||
mkdir -p $dir
|
||||
mv *.lua $dir
|
||||
cp *.lua $dir
|
||||
for d in *; do
|
||||
if [[ -d "$d" ]] && [[ "$d" != 'lua' ]]; then
|
||||
cp -r "$d" $dir
|
||||
fi
|
||||
done
|
||||
|
||||
cat <<'LUA' > $dir/dependencies.lua
|
||||
${pluginsLuaDef plugins}
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
local Dep = require 'sloth-flake.dep'
|
||||
|
||||
local M = {}
|
||||
|
||||
local function vim_error(...)
|
||||
vim.api.nvim_err_writeln(string.format(...))
|
||||
end
|
||||
|
||||
local commands = {
|
||||
list = function(args)
|
||||
local filter = args[1] or "all"
|
||||
local deps = vim.iter(Dep.all()):map(function (_, dep)
|
||||
return dep:name()
|
||||
end)
|
||||
if filter == "all" then
|
||||
-- Nothing to do
|
||||
elseif filter == "loaded" then
|
||||
deps = deps:filter(function (dep)
|
||||
return Dep.get(dep):is_loaded()
|
||||
end)
|
||||
elseif filter == "notloaded" then
|
||||
deps = deps:filter(function (dep)
|
||||
return not Dep.get(dep):is_loaded()
|
||||
end)
|
||||
else
|
||||
vim_error([[No Sloth list filter "%s".]], cmd)
|
||||
vim_error("Filters are: all, loaded, notloaded")
|
||||
return
|
||||
end
|
||||
deps = deps:totable()
|
||||
table.sort(deps)
|
||||
for _, dep in ipairs(deps) do
|
||||
print(string.format("- %s", dep))
|
||||
end
|
||||
end,
|
||||
|
||||
load = function(plugins)
|
||||
if #plugins == 0 then
|
||||
vim_error("You should at least give a plugin to load!")
|
||||
return
|
||||
end
|
||||
for _, plugin in ipairs(plugins) do
|
||||
local dep = Dep.get(plugin)
|
||||
if dep ~= nil then
|
||||
dep:load()
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
version = function()
|
||||
local version = require('sloth-flake.version')
|
||||
print(string.format('Sloth v%s', version()))
|
||||
end,
|
||||
}
|
||||
|
||||
function sloth_cmd(param)
|
||||
local args = param.fargs
|
||||
local cmd = args[1] or "list";
|
||||
table.remove(args, 1)
|
||||
local fn = commands[cmd]
|
||||
if fn then
|
||||
fn(args)
|
||||
else
|
||||
vim.api.nvim_err_writeln(string.format([[No Sloth subcommand "%s"]], cmd))
|
||||
end
|
||||
end
|
||||
|
||||
function M.register()
|
||||
vim.api.nvim_create_user_command('Sloth', sloth_cmd, {
|
||||
nargs = '*',
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
local Dep = require 'sloth-flake.dep'
|
||||
|
||||
local M = {}
|
||||
|
||||
local commands = {
|
||||
list = require 'sloth-flake.command.list',
|
||||
load = require 'sloth-flake.command.load',
|
||||
version = require 'sloth-flake.command.version',
|
||||
}
|
||||
|
||||
function sloth_cmd(param)
|
||||
local args = param.fargs
|
||||
local cmd = args[1] or "list";
|
||||
table.remove(args, 1)
|
||||
local fn = commands[cmd]
|
||||
if fn then
|
||||
fn(args)
|
||||
else
|
||||
vim.api.nvim_err_writeln(string.format([[No Sloth subcommand "%s"]], cmd))
|
||||
end
|
||||
end
|
||||
|
||||
function M.register()
|
||||
vim.api.nvim_create_user_command('Sloth', sloth_cmd, {
|
||||
nargs = '*',
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
local Dep = require 'sloth-flake.dep'
|
||||
local utils = require 'sloth-flake.utils'
|
||||
|
||||
return function(args)
|
||||
local filter = args[1] or "all"
|
||||
local deps = vim.iter(Dep.all()):map(function(_, dep)
|
||||
return dep:name()
|
||||
end)
|
||||
if filter == "all" then
|
||||
-- Nothing to do
|
||||
elseif filter == "loaded" then
|
||||
deps = deps:filter(function(dep)
|
||||
return Dep.get(dep):is_loaded()
|
||||
end)
|
||||
elseif filter == "notloaded" then
|
||||
deps = deps:filter(function(dep)
|
||||
return not Dep.get(dep):is_loaded()
|
||||
end)
|
||||
else
|
||||
utils.error([[No Sloth list filter "%s".]], cmd)
|
||||
utils.error("Filters are: all, loaded, notloaded")
|
||||
return
|
||||
end
|
||||
deps = deps:totable()
|
||||
table.sort(deps)
|
||||
for _, dep in ipairs(deps) do
|
||||
print(string.format("- %s", dep))
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
local Dep = require 'sloth-flake.dep'
|
||||
local utils = require 'sloth-flake.utils'
|
||||
|
||||
return function(plugins)
|
||||
if #plugins == 0 then
|
||||
utils.error("You should at least give a plugin to load!")
|
||||
return
|
||||
end
|
||||
for _, plugin in ipairs(plugins) do
|
||||
local dep = Dep.get(plugin)
|
||||
if dep ~= nil then
|
||||
dep:load()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
return function()
|
||||
local version = require('sloth-flake.version')
|
||||
print(string.format('Sloth v%s', version()))
|
||||
end
|
||||
|
|
@ -89,7 +89,6 @@ function M:import()
|
|||
end
|
||||
|
||||
function M:load()
|
||||
-- unshim_plugin(name)
|
||||
self:unshim()
|
||||
self:init()
|
||||
self:import()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
function M.error(...)
|
||||
vim.api.nvim_err_writeln(string.format(...))
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Reference in New Issue