Software / code / prosody
Comparison
spec/util_argparse_spec.lua @ 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 |
| parent | 11845:97c1399720c2 |
| child | 13160:4ee9a912ceea |
comparison
equal
deleted
inserted
replaced
| 12475:553c6204fe5b | 12477:cc84682b8429 |
|---|---|
| 18 | 18 |
| 19 it("consumes input until the first argument", function() | 19 it("consumes input until the first argument", function() |
| 20 local arg = { "--foo"; "bar"; "--baz" }; | 20 local arg = { "--foo"; "bar"; "--baz" }; |
| 21 local opts, err = parse(arg); | 21 local opts, err = parse(arg); |
| 22 assert.falsy(err); | 22 assert.falsy(err); |
| 23 assert.same({ foo = true }, opts); | 23 assert.same({ foo = true, "bar", "--baz" }, opts); |
| 24 assert.same({ "bar"; "--baz" }, arg); | 24 assert.same({ "bar"; "--baz" }, arg); |
| 25 end); | 25 end); |
| 26 | 26 |
| 27 it("expands short options", function() | 27 it("expands short options", function() |
| 28 local opts, err = parse({ "--foo"; "-b" }, { short_params = { b = "bar" } }); | 28 local opts, err = parse({ "--foo"; "-b" }, { short_params = { b = "bar" } }); |