From: Tobias Ulmer Date: Tue, 10 Jul 2012 12:27:59 +0000 (+0200) Subject: Add call_tool_argv(), which takes separated arguments in a table X-Git-Tag: e2factory-2.3.12rc1~29 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=5624b597288997755c59b033d018ee758905db90;p=e2factory.git Add call_tool_argv(), which takes separated arguments in a table Allows us to quote arguments in a single place, right before calling out to the shell. In the long term, call_tool() should die. Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 9c57801..414010c 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1528,6 +1528,36 @@ function call_tool(tool, args) return true, e end +--- call a tool with argv +-- @param tool string: tool name as registered in the tools library +-- @param argv table: a vector of (string) arguments +-- @return bool +-- @return string: the last line ouf captured output +function call_tool_argv(tool, argv) + local cmd = tools.get_tool(tool) + if not cmd then + bomb("trying to call invalid tool: " .. tostring(tool)) + end + local flags = tools.get_tool_flags(tool) + if not flags then + bomb("invalid tool flags for tool: " .. tostring(tool)) + end + + -- TODO: flags should be quoted as well, requires config changes + local call = string.format("%s %s", e2lib.shquote(cmd), flags) + + for _,arg in ipairs(argv) do + assert(type(arg) == "string") + call = call .. " " .. e2lib.shquote(arg) + end + + local rc, e = callcmd_log(call) + if rc ~= 0 then + return false, e + end + return true, e +end + --- call git -- @param gitdir string: GIT_DIR (optional, defaults to ".git") -- @param subtool string: git tool name