Skip to content

Commit aa6390a

Browse files
o-limamireh
authored andcommitted
Add -- as marker for end of options
Any parameter specified after a `--` is treated as a positional argument.
1 parent 6f24d29 commit aa6390a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

spec/cliargs_parsing_spec.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,24 @@ describe("Testing cliargs library parsing commandlines", function()
230230
assert.is.falsy(result)
231231
end)
232232

233-
it("tests optionals + required, no optionals and to many required provided, ", function()
233+
it("tests optionals + required, no optionals and too many required provided, ", function()
234234
populate_required(cli)
235235
populate_optionals(cli)
236236
result = cli:parse({ "some_file", "some_other_file" }, true --[[no print]])
237237
assert.is.falsy(result)
238238
end)
239239

240+
it("tests optionals + required + optarg, '--' as end of optionals", function()
241+
populate_required(cli)
242+
populate_optarg(1)
243+
local expected = populate_flags(cli)
244+
expected.INPUT = "--input"
245+
expected.OUTPUT = "-d"
246+
expected.verbose = true
247+
local result = cli:parse({ "--verbose", "--", "--input", "-d" })
248+
assert.is.same(expected, result)
249+
end)
250+
240251
it("tests bad short-key notation, -x=VALUE", function()
241252
populate_optionals(cli)
242253
result = cli:parse({ "-o=some_file" }, true --[[no print]])

src/cliargs.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ function cli:parse(arguments, noprint, dump)
312312
break -- no optional prefix, so options are done
313313
end
314314

315+
if opt == "--" then
316+
table.remove(args, 1)
317+
break -- end of options
318+
end
319+
315320
if optkey:sub(-1,-1) == "=" then -- check on a blank value eg. --insert=
316321
optval = ""
317322
optkey = optkey:sub(1,-2)

0 commit comments

Comments
 (0)