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
|
2022-11-29 09:56:17 +00:00
|
|
|
---@param plugins? LazyPlugin[]
|
|
|
|
function M.cmd(cmd, plugins)
|
2022-12-17 14:56:13 +00:00
|
|
|
cmd = cmd == "" and "home" or cmd
|
2022-11-20 22:25:28 +00:00
|
|
|
local command = M.commands[cmd]
|
|
|
|
if command == nil then
|
|
|
|
Util.error("Invalid lazy command '" .. cmd .. "'")
|
|
|
|
else
|
2022-11-29 09:56:17 +00:00
|
|
|
command(plugins)
|
2022-11-20 22:25:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-18 10:42:27 +00:00
|
|
|
---@class LazyCommands
|
2022-11-20 22:25:28 +00:00
|
|
|
M.commands = {
|
2022-11-29 09:56:17 +00:00
|
|
|
clean = function(plugins)
|
2022-11-30 22:14:16 +00:00
|
|
|
Manage.clean({ clear = true, mode = "clean", plugins = plugins })
|
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-30 22:14:16 +00:00
|
|
|
Manage.install({ clear = true, mode = "install" })
|
2022-11-22 20:12:50 +00:00
|
|
|
end,
|
2022-11-29 09:56:17 +00:00
|
|
|
log = function(plugins)
|
2022-11-30 22:14:16 +00:00
|
|
|
Manage.log({ clear = true, mode = "log", plugins = plugins })
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
2022-12-17 14:56:13 +00:00
|
|
|
home = function()
|
|
|
|
View.show("home")
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
2022-12-18 10:42:27 +00:00
|
|
|
show = function()
|
|
|
|
View.show("home")
|
|
|
|
end,
|
2022-11-29 09:30:14 +00:00
|
|
|
help = function()
|
|
|
|
View.show("help")
|
|
|
|
end,
|
2022-12-05 13:46:46 +00:00
|
|
|
debug = function()
|
|
|
|
View.show("debug")
|
|
|
|
end,
|
2022-11-29 11:02:25 +00:00
|
|
|
profile = function()
|
|
|
|
View.show("profile")
|
|
|
|
end,
|
2022-11-20 22:25:28 +00:00
|
|
|
sync = function()
|
2022-11-30 22:14:16 +00:00
|
|
|
Manage.clean({ clear = true, wait = true, mode = "sync" })
|
2022-12-18 10:42:27 +00:00
|
|
|
Manage.update()
|
|
|
|
Manage.install()
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
2022-11-29 09:56:17 +00:00
|
|
|
update = function(plugins)
|
2022-11-30 22:14:16 +00:00
|
|
|
Manage.update({ clear = true, mode = "update", plugins = plugins })
|
2022-11-20 22:25:28 +00:00
|
|
|
end,
|
2022-11-29 09:56:17 +00:00
|
|
|
check = function(plugins)
|
2022-11-30 22:14:16 +00:00
|
|
|
Manage.check({ clear = true, mode = "check", plugins = plugins })
|
2022-11-29 07:23:23 +00:00
|
|
|
end,
|
2022-11-29 09:56:17 +00:00
|
|
|
restore = function(plugins)
|
2022-11-30 22:14:16 +00:00
|
|
|
Manage.update({ clear = true, lockfile = true, mode = "restore", plugins = plugins })
|
2022-11-28 23:15:13 +00:00
|
|
|
end,
|
2022-11-20 22:25:28 +00: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
|