# HG changeset patch # User Matthew Wild # Date 1650896696 -3600 # Node ID cc84682b8429c15f9232201eca66f9a1394f3fdd # Parent 553c6204fe5b40a731c81d370b42917dfee37530 util.argparse: Revise 553c6204fe5b with a different approach The second return value is (not insensibly) assumed to be an error. Instead of returning a value there in the success case, copy the positional arguments into the existing opts table. diff -r 553c6204fe5b -r cc84682b8429 spec/util_argparse_spec.lua --- a/spec/util_argparse_spec.lua Mon Apr 25 15:09:41 2022 +0100 +++ b/spec/util_argparse_spec.lua Mon Apr 25 15:24:56 2022 +0100 @@ -20,7 +20,7 @@ local arg = { "--foo"; "bar"; "--baz" }; local opts, err = parse(arg); assert.falsy(err); - assert.same({ foo = true }, opts); + assert.same({ foo = true, "bar", "--baz" }, opts); assert.same({ "bar"; "--baz" }, arg); end); diff -r 553c6204fe5b -r cc84682b8429 util/argparse.lua --- a/util/argparse.lua Mon Apr 25 15:09:41 2022 +0100 +++ b/util/argparse.lua Mon Apr 25 15:24:56 2022 +0100 @@ -5,7 +5,7 @@ local parsed_opts = {}; if #arg == 0 then - return parsed_opts, arg; + return parsed_opts; end while true do local raw_param = arg[1]; @@ -47,7 +47,10 @@ end parsed_opts[param_k] = param_v; end - return parsed_opts, arg; + for i = 1, #arg do + parsed_opts[i] = arg[i]; + end + return parsed_opts; end return {