]> git.e2factory.org Git - e2factory.git/commitdiff
e2option: make default for option flags functional
authorTobias Ulmer <tu@emlix.com>
Mon, 6 Feb 2017 15:51:26 +0000 (16:51 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 6 Feb 2017 15:51:26 +0000 (16:51 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2option.lua

index 43754704ea35ef449b65954c57f063dff18335fd..4f5cdcfc54321a2b1454b65056fea47a43fb9ece 100644 (file)
@@ -71,8 +71,8 @@ function e2option.option(name, doc, default, func, argname)
     options[name] = {
         type = "option",
         documentation = doc or "", name = name,
-        proc=func,
-        default=default or true,
+        proc = func,
+        default = default,
         argumentname=argname or "ARGUMENT"
     }
 end
@@ -340,14 +340,24 @@ function e2option.parse(args)
                 if options[opt] then
                     local proc = options[opt].proc
                     if options[opt].type == "option" then
+                        local optarg
+
                         if i == #args then
-                            return false,
-                                err.new("argument missing for option: %s", opt)
+                            if options[opt].default == nil then
+                                return false,
+                                    err.new("argument missing for option: %s",
+                                        opt)
+                            else
+                                optarg = options[opt].default
+                            end
+                        else
+                            optarg =  args[i + 1]
                         end
+
                         if proc then
-                            opts[opt] = proc(args[i + 1])
+                            opts[opt] = proc(optarg)
                         else
-                            opts[opt] = args[i + 1]
+                            opts[opt] = optarg
                         end
                         i = i + 1
                     else