mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
More properties for configuring usage and help messages
* `usage_margin`: sets margin for the second and following lines of usage string. * `usage_max_width`: sets usage max width for autowrapping. * `help_usage_margin`: sets margin for element usages in help string. * `help_description`: sets margin for element descrptions in help string.
This commit is contained in:
@@ -463,4 +463,37 @@ Options:
|
||||
|
||||
-h, --help Show this help message and exit.]], cmd2:get_help())
|
||||
end)
|
||||
|
||||
it("allows configuring margins using help_usage_margin and help_description_margin", function()
|
||||
local parser = Parser "foo"
|
||||
:help_usage_margin(2)
|
||||
:help_description_margin(15)
|
||||
|
||||
parser:argument "arg1"
|
||||
:description "Argument number one."
|
||||
parser:argument "arg2"
|
||||
:description "Argument number two."
|
||||
|
||||
parser:flag "-p"
|
||||
:description "This is a thing."
|
||||
parser:option "-f --foo"
|
||||
:description [[
|
||||
And this things uses many lines.
|
||||
Because it has lots of complex behaviour.
|
||||
That needs documenting.]]
|
||||
|
||||
assert.equal([[
|
||||
Usage: foo [-p] [-f <foo>] [-h] <arg1> <arg2>
|
||||
|
||||
Arguments:
|
||||
arg1 Argument number one.
|
||||
arg2 Argument number two.
|
||||
|
||||
Options:
|
||||
-p This is a thing.
|
||||
-f <foo>, And this things uses many lines.
|
||||
--foo <foo> Because it has lots of complex behaviour.
|
||||
That needs documenting.
|
||||
-h, --help Show this help message and exit.]], parser:get_help())
|
||||
end)
|
||||
end)
|
||||
|
@@ -307,4 +307,38 @@ Usage: foo ([--opt1 <opt1>] | [--opt3 <opt3>] | [--opt5 <opt5>])
|
||||
([<arg4>] | [--opt4 <opt4>])]=], parser:get_usage()
|
||||
)
|
||||
end)
|
||||
|
||||
it("allows configuring usage margin using usage_margin property", function()
|
||||
local parser = Parser "foo"
|
||||
:usage_margin(2)
|
||||
|
||||
parser:argument "long_argument_name"
|
||||
parser:argument "very_long_words"
|
||||
|
||||
parser:option "--set-important-property"
|
||||
parser:option "--include"
|
||||
:args "*"
|
||||
|
||||
assert.equals([=[
|
||||
Usage: foo [--set-important-property <set_important_property>] [-h]
|
||||
<long_argument_name> <very_long_words> [--include [<include>] ...]]=], parser:get_usage())
|
||||
end)
|
||||
|
||||
it("allows configuring max usage width using usage_max_width property", function()
|
||||
local parser = Parser "foo"
|
||||
:usage_max_width(50)
|
||||
|
||||
parser:argument "long_argument_name"
|
||||
parser:argument "very_long_words"
|
||||
|
||||
parser:option "--set-important-property"
|
||||
parser:option "--include"
|
||||
:args "*"
|
||||
|
||||
assert.equals([=[
|
||||
Usage: foo
|
||||
[--set-important-property <set_important_property>]
|
||||
[-h] <long_argument_name> <very_long_words>
|
||||
[--include [<include>] ...]]=], parser:get_usage())
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user