Improved help option behaviour

* Help option is only created once per parser, several :prepare() invocations do not create extra options.
* In :add_help(foo), foo is passed to the help option overriding default name, see spec/help_spec.lua @ 24
This commit is contained in:
mpeterv
2014-02-17 16:58:16 +04:00
parent 06912106dc
commit 3788b9c1a6
2 changed files with 32 additions and 3 deletions

View File

@@ -11,6 +11,27 @@ describe("tests related to help message generation", function()
}, "\r\n"), parser:prepare():get_help())
end)
it("does not create extra help options when :prepare is called several times", function()
local parser = argparse.parser "foo"
assert.equal(table.concat({
"Usage: foo [-h]",
"",
"Options: ",
" -h, --help Show this help message and exit. "
}, "\r\n"), parser:prepare():prepare():get_help())
end)
it("uses custom help option", function()
local parser = argparse.parser "foo"
:add_help {aliases = {"\\?"}}
assert.equal(table.concat({
"Usage: foo [\\?]",
"",
"Options: ",
" \\? Show this help message and exit. "
}, "\r\n"), parser:prepare():get_help())
end)
it("creates correct help message for arguments", function()
local parser = argparse.parser "foo"
parser:argument "first"