lazy.nvim/lua/lazy/view/commands.lua

93 lines
2.1 KiB
Lua
Raw Normal View History

2022-11-21 06:25:28 +08:00
local View = require("lazy.view")
local Manage = require("lazy.manage")
local Util = require("lazy.util")
2022-11-21 06:25:28 +08:00
local M = {}
---@param cmd string
---@param plugins? LazyPlugin[]
function M.cmd(cmd, plugins)
cmd = cmd == "" and "home" or cmd
2022-11-21 06:25:28 +08:00
local command = M.commands[cmd]
if command == nil then
Util.error("Invalid lazy command '" .. cmd .. "'")
else
command(plugins)
2022-11-21 06:25:28 +08:00
end
end
M.commands = {
clean = function(plugins)
2022-12-01 06:14:16 +08:00
Manage.clean({ clear = true, mode = "clean", plugins = plugins })
2022-11-21 06:25:28 +08:00
end,
clear = function()
Manage.clear()
View.show()
end,
2022-11-21 06:25:28 +08:00
install = function()
2022-12-01 06:14:16 +08:00
Manage.install({ clear = true, mode = "install" })
2022-11-23 04:12:50 +08:00
end,
log = function(plugins)
2022-12-01 06:14:16 +08:00
Manage.log({ clear = true, mode = "log", plugins = plugins })
2022-11-21 06:25:28 +08:00
end,
home = function()
View.show("home")
2022-11-21 06:25:28 +08:00
end,
2022-11-29 17:30:14 +08:00
help = function()
View.show("help")
end,
debug = function()
View.show("debug")
end,
2022-11-29 19:02:25 +08:00
profile = function()
View.show("profile")
end,
2022-11-21 06:25:28 +08:00
sync = function()
2022-12-01 06:14:16 +08:00
Manage.clean({ clear = true, wait = true, mode = "sync" })
2022-11-28 20:11:41 +08:00
Manage.update({ interactive = true })
Manage.install({ interactive = true })
2022-11-21 06:25:28 +08:00
end,
update = function(plugins)
2022-12-01 06:14:16 +08:00
Manage.update({ clear = true, mode = "update", plugins = plugins })
2022-11-21 06:25:28 +08:00
end,
check = function(plugins)
2022-12-01 06:14:16 +08:00
Manage.check({ clear = true, mode = "check", plugins = plugins })
end,
restore = function(plugins)
2022-12-01 06:14:16 +08:00
Manage.update({ clear = true, lockfile = true, mode = "restore", plugins = plugins })
2022-11-29 07:15:13 +08:00
end,
2022-11-21 06:25:28 +08:00
}
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