Avoid printing space at the end of line

This commit is contained in:
mpeterv
2015-03-13 15:40:24 +03:00
parent 01cc387863
commit 476ad19de8
3 changed files with 33 additions and 33 deletions

View File

@@ -7,8 +7,8 @@ describe("tests related to help message generation", function()
assert.equal([[ assert.equal([[
Usage: foo [-h] Usage: foo [-h]
Options: Options:
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("does not create extra help options when :prepare is called several times", function() it("does not create extra help options when :prepare is called several times", function()
@@ -16,8 +16,8 @@ Options:
assert.equal([[ assert.equal([[
Usage: foo [-h] Usage: foo [-h]
Options: Options:
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("uses custom help option ", function() it("uses custom help option ", function()
@@ -26,8 +26,8 @@ Options:
assert.equal([[ assert.equal([[
Usage: foo [/?] Usage: foo [/?]
Options: Options:
/? Show this help message and exit. ]], parser:get_help()) /? Show this help message and exit.]], parser:get_help())
end) end)
it("uses description and epilog", function() it("uses description and epilog", function()
@@ -40,8 +40,8 @@ Usage: foo [-h]
A description. A description.
Options: Options:
-h, --help Show this help message and exit. -h, --help Show this help message and exit.
An epilog. ]], parser:get_help()) An epilog. ]], parser:get_help())
end) end)
@@ -61,14 +61,14 @@ An epilog. ]], parser:get_help())
Usage: foo [-h] <first> <second-and-third> <second-and-third> Usage: foo [-h] <first> <second-and-third> <second-and-third>
[<maybe-fourth>] [<others>] ... [<maybe-fourth>] [<others>] ...
Arguments: Arguments:
first first
second-and-third second-and-third
maybe-fourth maybe-fourth
others Optional. others Optional.
Options: Options:
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("creates correct help message for options", function() it("creates correct help message for options", function()
@@ -82,11 +82,11 @@ Options:
assert.equal([[ assert.equal([[
Usage: foo [-q] --from <from> [--config <config>] [-h] Usage: foo [-q] --from <from> [--config <config>] [-h]
Options: Options:
-q, --quiet -q, --quiet
--from <from> --from <from>
--config <config> --config <config>
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("adds margin for multiline descriptions", function() it("adds margin for multiline descriptions", function()
@@ -102,11 +102,11 @@ Sets verbosity level.
assert.equal([[ assert.equal([[
Usage: foo [-v] [-h] Usage: foo [-v] [-h]
Options: Options:
-v Sets verbosity level. -v Sets verbosity level.
-v: Report all warnings. -v: Report all warnings.
-vv: Report all debugging information. -vv: Report all debugging information.
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("shows default values", function() it("shows default values", function()
@@ -120,10 +120,10 @@ Options:
assert.equal([[ assert.equal([[
Usage: foo [-o <o>] [-p <p>] [-h] Usage: foo [-o <o>] [-p <p>] [-h]
Options: Options:
-o <o> default: a.out -o <o> default: a.out
-p <p> Port. (default: 8080) -p <p> Port. (default: 8080)
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("does not show default value when show_default == false", function() it("does not show default value when show_default == false", function()
@@ -139,10 +139,10 @@ Options:
assert.equal([[ assert.equal([[
Usage: foo [-o <o>] [-p <p>] [-h] Usage: foo [-o <o>] [-p <p>] [-h]
Options: Options:
-o <o> -o <o>
-p <p> Port. -p <p> Port.
-h, --help Show this help message and exit. ]], parser:get_help()) -h, --help Show this help message and exit.]], parser:get_help())
end) end)
it("creates correct help message for commands", function() it("creates correct help message for commands", function()
@@ -155,11 +155,11 @@ Options:
assert.equal([[ assert.equal([[
Usage: foo [-q] [-h] <command> ... Usage: foo [-q] [-h] <command> ...
Options: Options:
-q, --quiet -q, --quiet
-h, --help Show this help message and exit. -h, --help Show this help message and exit.
Commands: Commands:
run Run! ]], parser:get_help()) run Run! ]], parser:get_help())
end) end)
@@ -172,9 +172,9 @@ Commands:
assert.equal([[ assert.equal([[
Usage: foo run [--where <where>] [-h] Usage: foo run [--where <where>] [-h]
Options: Options:
--where <where> --where <where>
-h, --help Show this help message and exit. ]], run:get_help()) -h, --help Show this help message and exit.]], run:get_help())
end) end)
it("uses message provided by user", function() it("uses message provided by user", function()

View File

@@ -74,14 +74,14 @@ Usage: ./spec/script [-v] [-h] <input> [<command>] ...
A testing program. A testing program.
Arguments: Arguments:
input input
Options: Options:
-v, --verbose Sets verbosity level. -v, --verbose Sets verbosity level.
-h, --help Show this help message and exit. -h, --help Show this help message and exit.
Commands: Commands:
install Install a rock. install Install a rock.
]], get_output("--help")) ]], get_output("--help"))
end) end)
@@ -92,14 +92,14 @@ Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]
Install a rock. Install a rock.
Arguments: Arguments:
rock Name of the rock. rock Name of the rock.
version Version of the rock. version Version of the rock.
Options: Options:
-f <from>, --from <from> -f <from>, --from <from>
Fetch the rock from this server. Fetch the rock from this server.
-h, --help Show this help message and exit. -h, --help Show this help message and exit.
]], get_output("foo install --help")) ]], get_output("foo install --help"))
end) end)
end) end)

View File

@@ -167,7 +167,7 @@ do
if param then if param then
local help = self:flag() local help = self:flag()
:description "Show this help message and exit. " :description "Show this help message and exit."
:action(function() :action(function()
io.stdout:write(self:get_help() .. "\n") io.stdout:write(self:get_help() .. "\n")
os.exit(0) os.exit(0)
@@ -581,7 +581,7 @@ function Parser:get_help()
table.insert(blocks, self._description) table.insert(blocks, self._description)
end end
local labels = {"Arguments: ", "Options: ", "Commands: "} local labels = {"Arguments:", "Options:", "Commands:"}
for i, elements in ipairs{self._arguments, self._options, self._commands} do for i, elements in ipairs{self._arguments, self._options, self._commands} do
if #elements > 0 then if #elements > 0 then