2022-11-20 22:25:28 +00:00
|
|
|
local View = require("lazy.view")
|
2022-11-27 10:02:28 +00:00
|
|
|
local Manage = require("lazy.manage")
|
2022-11-24 21:04:23 +00:00
|
|
|
local Util = require("lazy.util")
|
2022-11-20 22:25:28 +00:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
---@param cmd string
|
|
|
|
function M.cmd(cmd)
|
|
|
|
cmd = cmd == "" and "show" or cmd
|
|
|
|
local command = M.commands[cmd]
|
|
|
|
if command == nil then
|
|
|
|
Util.error("Invalid lazy command '" .. cmd .. "'")
|
|
|
|
else
|
|
|
|
command()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
M.commands = {
|
|
|
|
clean = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.clean({ clear = true, show = true })
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
2022-11-23 15:12:02 +00:00
|
|
|
clear = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.clear()
|
2022-11-23 15:12:02 +00:00
|
|
|
View.show()
|
|
|
|
end,
|
2022-11-20 22:25:28 +00:00
|
|
|
install = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.install({ clear = true, show = true })
|
2022-11-22 20:12:50 +00:00
|
|
|
end,
|
|
|
|
log = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.log({ clear = true, show = true })
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
|
|
|
show = function()
|
|
|
|
View.show()
|
|
|
|
end,
|
2022-11-23 15:12:02 +00:00
|
|
|
docs = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.docs({ clear = true, show = true })
|
2022-11-23 15:12:02 +00:00
|
|
|
end,
|
2022-11-20 22:25:28 +00:00
|
|
|
sync = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.update({ clear = true, show = true })
|
|
|
|
Manage.install({ show = true })
|
|
|
|
Manage.clean({ show = true })
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
|
|
|
update = function()
|
2022-11-27 10:02:28 +00:00
|
|
|
Manage.update({ clear = true, show = true })
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
function M.setup()
|
|
|
|
vim.api.nvim_create_user_command("Lazy", function(args)
|
|
|
|
M.cmd(vim.trim(args.args or ""))
|
|
|
|
end, {
|
|
|
|
nargs = "?",
|
|
|
|
desc = "Lazy",
|
|
|
|
complete = function(_, line)
|
|
|
|
if line:match("^%s*Lazy %w+ ") then
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local prefix = line:match("^%s*Lazy (%w*)") or ""
|
|
|
|
|
|
|
|
---@param key string
|
|
|
|
return vim.tbl_filter(function(key)
|
|
|
|
return key:find(prefix) == 1
|
|
|
|
end, vim.tbl_keys(M.commands))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
for name in pairs(M.commands) do
|
|
|
|
local cmd = "Lazy" .. name:sub(1, 1):upper() .. name:sub(2)
|
|
|
|
|
|
|
|
vim.api.nvim_create_user_command(cmd, function()
|
|
|
|
M.cmd(name)
|
|
|
|
end, {
|
|
|
|
desc = "Lazy " .. name,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|