]> git.e2factory.org Git - e2factory.git/commitdiff
Add call_tool_argv(), which takes separated arguments in a table
authorTobias Ulmer <tu@emlix.com>
Tue, 10 Jul 2012 12:27:59 +0000 (14:27 +0200)
committerTobias Ulmer <tu@emlix.com>
Tue, 10 Jul 2012 12:27:59 +0000 (14:27 +0200)
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 <tu@emlix.com>
generic/e2lib.lua

index 9c57801ae516908dacdcb95eb6e4d69e2a2d7e09..414010cb9e0bcb2e257b0b7b731a6529b98cb020 100644 (file)
@@ -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