mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Add hidden
property, unlisting elements from usage and help
This commit is contained in:
@@ -182,4 +182,46 @@ Options:
|
||||
assert.equal([[
|
||||
I don't like your format of help messages]], parser:get_help())
|
||||
end)
|
||||
|
||||
it("does not mention hidden arguments, options, and commands", function()
|
||||
local parser = Parser "foo"
|
||||
parser:argument "normal"
|
||||
parser:argument "deprecated"
|
||||
:args "?"
|
||||
:hidden(true)
|
||||
parser:flag "--feature"
|
||||
parser:flag "--misfeature"
|
||||
:hidden(true)
|
||||
parser:command "good"
|
||||
parser:command "okay"
|
||||
parser:command "never-use-this-one"
|
||||
:hidden(true)
|
||||
|
||||
assert.equal([[
|
||||
Usage: foo [--feature] [-h] <normal> <command> ...
|
||||
|
||||
Arguments:
|
||||
normal
|
||||
|
||||
Options:
|
||||
--feature
|
||||
-h, --help Show this help message and exit.
|
||||
|
||||
Commands:
|
||||
good
|
||||
okay]], parser:get_help())
|
||||
end)
|
||||
|
||||
it("omits categories if all elements are hidden", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
parser:argument "deprecated"
|
||||
:args "?"
|
||||
:hidden(true)
|
||||
parser:flag "--misfeature"
|
||||
:hidden(true)
|
||||
|
||||
assert.equal([[
|
||||
Usage: foo]], parser:get_help())
|
||||
end)
|
||||
end)
|
||||
|
@@ -116,6 +116,42 @@ Usage: foo <first> <second-and-third> <second-and-third>
|
||||
)
|
||||
end)
|
||||
|
||||
it("omits usage for hidden arguments and options", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
parser:flag "-d" "--deprecated"
|
||||
:hidden(true)
|
||||
parser:flag "-n" "--not-deprecated"
|
||||
parser:argument "normal"
|
||||
parser:argument "deprecated"
|
||||
:args "?"
|
||||
:hidden(true)
|
||||
|
||||
assert.equal(
|
||||
[=[Usage: foo [-n] <normal>]=],
|
||||
parser:get_usage()
|
||||
)
|
||||
end)
|
||||
|
||||
it("omits usage for mutexes if all elements are hidden", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
parser:mutex(
|
||||
parser:flag "--misfeature"
|
||||
:hidden(true),
|
||||
parser:flag "--no-misfeature"
|
||||
:action "store_false"
|
||||
:target "misfeature"
|
||||
:hidden(true)
|
||||
)
|
||||
parser:flag "--feature"
|
||||
|
||||
assert.equal(
|
||||
[=[Usage: foo [--feature]]=],
|
||||
parser:get_usage()
|
||||
)
|
||||
end)
|
||||
|
||||
it("usage messages for commands are correct after several invocations", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
|
Reference in New Issue
Block a user