diff --git a/README.md b/README.md index e8b5448..bcd12a9 100644 --- a/README.md +++ b/README.md @@ -264,10 +264,12 @@ You can define and run arbitrary commands on yaml files, for instance: trivy = { cmd = "trivy", args = { "-q", "fs" }, + timeout = 10000, -- in ms }, deprecations29 = { cmd = "kubent", args = { "-t", "1.29", "-c=false", "--helm3=false", "-l=error", "-e", "-f" }, + -- the default timeout is 5000 when not specified }, deprecations30 = { cmd = "kubent", diff --git a/lua/kustomize/init.lua b/lua/kustomize/init.lua index 59ac735..6fb69dc 100644 --- a/lua/kustomize/init.lua +++ b/lua/kustomize/init.lua @@ -16,12 +16,12 @@ M.set_default_mappings = function() vim.keymap.set("n", "kv", function() local validate = config.options.run.validate - run.run_checked(validate.cmd, validate.args) + run.run_checked(validate.cmd, validate.args, validate.timeout or 5000) end, { desc = "Validate manifests" }) vim.keymap.set("n", "kd", function() local deprecate = config.options.run.deprecations - run.run_checked(deprecate.cmd, deprecate.args) + run.run_checked(deprecate.cmd, deprecate.args, deprecate.timeout or 5000) end, { desc = "Check for deprecations" }) end diff --git a/lua/kustomize/run.lua b/lua/kustomize/run.lua index 0908ef2..01cca8e 100644 --- a/lua/kustomize/run.lua +++ b/lua/kustomize/run.lua @@ -5,9 +5,10 @@ local M = {} ---comment ---@param cmd string ---@param args table +---@param timeout number ---@return table ---@return table -M.run = function(cmd, args) +M.run = function(cmd, args, timeout) if not utils.check_exec(cmd) then return { "cmd was not found on path" }, {} end @@ -28,13 +29,13 @@ M.run = function(cmd, args) table.insert(args, file_to_validate) - utils.info("Running: " .. cmd .. " " .. vim.inspect(args)) + utils.info("Running: " .. cmd .. " " .. vim.inspect(args) .. "timeout: " .. timeout) local Job = require("plenary.job") local job = Job:new({ command = cmd, args = args, }) - job:sync() + job:sync(timeout) local err, out = job:stderr_result(), job:result() -- Removes `file_to_validate` so that a second call does not include the first file_to_validate @@ -47,8 +48,8 @@ M.run = function(cmd, args) return err, out end -M.run_checked = function(cmd, args) - local err, out = M.run(cmd, args) +M.run_checked = function(cmd, args, timeout) + local err, out = M.run(cmd, args, timeout) if next(err) ~= nil then local err_msg = table.concat(err, "\n") diff --git a/plugin/kustomize.lua b/plugin/kustomize.lua index dffe661..e018282 100644 --- a/plugin/kustomize.lua +++ b/plugin/kustomize.lua @@ -20,7 +20,8 @@ vim.api.nvim_create_user_command("KustomizeRun", function(opts) local choice = opts.fargs[1] local cmd = config.options.run[choice].cmd local args = config.options.run[choice].args - run.run_checked(cmd, args) + local timeout = config.options.run[choice].timeout or 5000 + run.run_checked(cmd, args, timeout) end, { desc = "Run commands", nargs = 1,