]> git.e2factory.org Git - e2factory.git/commitdiff
Tighten argument parsing, fixes #1010
authorTobias Ulmer <tu@emlix.com>
Fri, 17 Aug 2012 12:27:09 +0000 (14:27 +0200)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:06 +0000 (19:07 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2option.lua

index 0cad0913642f404b5dcffc6fcd843b85eeb113aa..d6ea0942129ff9be5acd0c630e0de6b6b6516b03 100644 (file)
@@ -295,10 +295,21 @@ function e2option.parse(args)
         if s then
             opt = aliases[opt] or opt
             if options[opt] then
+                if options[opt].type == "flag" then
+                    e2lib.abort(string.format(
+                    "option '%s' does not take an argument\n"..
+                    "Try the --help option for usage information.", opt))
+                end
+
                 local proc = options[opt].proc
-                if proc then val = proc(val) end
+                if proc then
+                    val = proc(val)
+                end
+
                 opts[opt] = val
-            else e2option.usage(1)
+            else
+                e2lib.abort(string.format("unknown option: %s\n"..
+                "Try the --help option for usage information.", opt))
             end
         else
             s, e, opt = string.find(v, "^%-%-?(.*)$")
@@ -331,7 +342,7 @@ function e2option.parse(args)
 
                     for k, v in pairs(set) do
                         if not options[v] then
-                            e2lib.abort(string.format("invalid option: %s\n"..
+                            e2lib.abort(string.format("unknown option: %s\n"..
                             "Try the --help option for usage information.", opt))
                         else
                             table.insert(args, "-" .. v)