Software /
code /
prosody
Changeset
12477:cc84682b8429 0.12
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.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 25 Apr 2022 15:24:56 +0100 |
parents | 12475:553c6204fe5b |
children | 12478:82270a6b1234 12479:4d36fbcdd210 |
files | spec/util_argparse_spec.lua util/argparse.lua |
diffstat | 2 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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 {