mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Add 'concat' action
This commit is contained in:
@@ -100,9 +100,10 @@ describe("actions", function()
|
|||||||
local parser = Parser()
|
local parser = Parser()
|
||||||
parser:flag("--no-foo"):target("foo"):action("store_false")
|
parser:flag("--no-foo"):target("foo"):action("store_false")
|
||||||
parser:flag("--no-bar"):target("bar"):action("store_false")
|
parser:flag("--no-bar"):target("bar"):action("store_false")
|
||||||
|
parser:option("--things"):args("+"):count("*"):action("concat")
|
||||||
|
|
||||||
local args = parser:parse{"--no-foo"}
|
local args = parser:parse{"--things", "a", "b", "--no-foo", "--things", "c", "d"}
|
||||||
assert.same({foo = false}, args)
|
assert.same({foo = false, things = {"a", "b", "c", "d"}}, args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("for options allow setting initial stored value", function()
|
it("for options allow setting initial stored value", function()
|
||||||
|
@@ -375,6 +375,16 @@ function actions.append(result, target, argument, overwrite)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function actions.concat(result, target, arguments, overwrite)
|
||||||
|
if overwrite then
|
||||||
|
error("'concat' action can't handle too many invocations")
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, argument in ipairs(arguments) do
|
||||||
|
table.insert(result[target], argument)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Argument:_get_action()
|
function Argument:_get_action()
|
||||||
local action, init
|
local action, init
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user