local core = require "core" local process = require "process" ---@class M local M = { name = "shell" } -- Run a shell command ---@param target table Target table ---@param name string Name of the target to run ---@praam debuginfo table Debugging information ---@return process|nil ---@diagnostic disable-next-line: unused-local function M:run(target, name, debuginfo) core.log("[jpdebug] Running shell command") local opts = { cwd = target.cwd or ".", env = target.env or {}, stdout = process.REDIRECT_PIPE, stderr = process.REDIRECT_PIPE } if target.cmd then local proc = process.start(target.cmd, opts) return proc else core.error("[jpdebug] command not specified for target %s", name) end end -- Wait untill it ends, possibly with timeout ---@param proc process Process object ---@param time any Time field, process.WAIT_INFINITE function M:wait(proc, time) return proc:wait(time) end -- Read the stdout, returns nil if process has stopped ---@param proc process Process object function M:read_stdout(proc) return proc:read_stdout() end -- Read the stderr ---@param proc process Process object function M:read_stderr(proc) return proc:read_stderr() end -- Kill the process ---@param proc process Process object function M:kill(proc) proc:kill() end -- Terminate the process ---@param proc process Process object function M:terminate(proc) proc:terminate() end return M