aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/util_argparse_spec.lua6
-rw-r--r--util/argparse.lua8
2 files changed, 12 insertions, 2 deletions
diff --git a/spec/util_argparse_spec.lua b/spec/util_argparse_spec.lua
index be1d99df..3fd4070e 100644
--- a/spec/util_argparse_spec.lua
+++ b/spec/util_argparse_spec.lua
@@ -54,6 +54,12 @@ describe("parse", function()
assert.same({ foo = "bar"; baz = "moo" }, opts);
end);
+ it("supports value arguments in strict mode", function()
+ local opts, err = parse({ "--foo"; "bar"; "--baz=moo" }, { strict = true, value_params = { foo = true; baz = true } });
+ assert.falsy(err);
+ assert.same({ foo = "bar"; baz = "moo" }, opts);
+ end);
+
it("demands values for value params", function()
local opts, err, where = parse({ "--foo" }, { value_params = { foo = true } });
assert.falsy(opts);
diff --git a/util/argparse.lua b/util/argparse.lua
index 3a7d1ba2..75b1c2f9 100644
--- a/util/argparse.lua
+++ b/util/argparse.lua
@@ -39,9 +39,13 @@ local function parse(arg, config)
local param_k, param_v;
if value_params[uparam] or array_params[uparam] then
- param_k, param_v = uparam, table.remove(arg, 1);
+ param_k = uparam;
+ param_v = param:match("^=(.*)$", #uparam+1);
if not param_v then
- return nil, "missing-value", raw_param;
+ param_v = table.remove(arg, 1);
+ if not param_v then
+ return nil, "missing-value", raw_param;
+ end
end
else
param_k, param_v = param:match("^([^=]+)=(.+)$");