]> git.e2factory.org Git - e2factory.git/commitdiff
extend the tools module with add_tool()
authorTobias Ulmer <tu@emlix.com>
Wed, 26 Jan 2011 18:15:53 +0000 (19:15 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 31 Jan 2011 11:09:10 +0000 (12:09 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/tools.lua

index f95092f9ba015bd5695f8f4dc128fa42e4c53588..1dede512760f173e7090de05759de2f398a40476 100644 (file)
@@ -104,6 +104,39 @@ function set_tool(name, value, flags)
        return true, nil
 end
 
+--- add a new tool
+-- @param name string: the tool name
+-- @param value string: the new tool command
+-- @param flags string: the new tool flags.
+-- @param optional bool: wheter the tool is optional or not
+-- @return bool
+-- @return nil, an error string on error
+function add_tool(name, value, flags, optional)
+       if tools[name] then
+               e2lib.bomb("trying to add a tool that already exists: " ..
+                       tostring(name))
+       end
+
+       if type(name) ~= "string" or type(value) ~= "string" or
+               type(flags) ~= "string" or type(optional) ~= "boolean" then
+               print("error in add_tool")
+               e2lib.bomb("one or more parameters wrong while adding tool " ..
+               tostring(name))
+       end
+
+       tools[name] = {
+               name = value,
+               flags = flags,
+               optional = optional,
+       }
+
+       local t = tools[name]
+       e2lib.log(3, string.format("adding tool: %s=%s flags=%s optional=%s",
+               name, t.name, t.flags, tostring(t.optional)))
+
+       return true, nil
+end
+
 --- check if a tool is available
 -- @param name string a valid tool name
 -- @return bool