Add :init() property

Allows setting initial stored value. Can be also set using
:default() with a non-string argument.
This commit is contained in:
mpeterv
2015-10-31 19:19:56 +03:00
parent 8343a41dfa
commit 38b6eb1392
2 changed files with 49 additions and 10 deletions

View File

@@ -105,6 +105,24 @@ describe("actions", function()
assert.same({foo = false}, args)
end)
it("for options allow setting initial stored value", function()
local parser = Parser()
parser:flag("--no-foo"):target("foo"):action("store_false"):init(true)
parser:flag("--no-bar"):target("bar"):action("store_false"):init(true)
local args = parser:parse{"--no-foo"}
assert.same({foo = false, bar = true}, args)
end)
it("for options allow setting initial stored value as non-string argument to default", function()
local parser = Parser()
parser:flag("--no-foo", "Foo the bar.", true):target("foo"):action("store_false")
parser:flag("--no-bar", "Bar the foo.", true):target("bar"):action("store_false")
local args = parser:parse{"--no-foo"}
assert.same({foo = false, bar = true}, args)
end)
it("pass overwrite flag as the fourth argument", function()
local parser = Parser()
local overwrites = {}