Custom target should not affect usage and help message generation

This commit is contained in:
mpeterv
2014-08-25 13:51:08 +04:00
parent b02536d6ba
commit bd5fd00e6c
4 changed files with 8 additions and 8 deletions

View File

@@ -85,11 +85,11 @@ describe("tests related to help message generation", function()
parser:option "--config" parser:option "--config"
assert.equal(table.concat({ assert.equal(table.concat({
"Usage: foo [-q] --from <server> [--config <config>] [-h]", "Usage: foo [-q] --from <from> [--config <config>] [-h]",
"", "",
"Options: ", "Options: ",
" -q, --quiet", " -q, --quiet",
" --from <server>", " --from <from>",
" --config <config>", " --config <config>",
" -h, --help Show this help message and exit. " " -h, --help Show this help message and exit. "
}, "\r\n"), parser:get_help()) }, "\r\n"), parser:get_help())

View File

@@ -60,7 +60,7 @@ describe("tests related to CLI behaviour #unsafe", function()
it("generates correct error message without arguments in command", function() it("generates correct error message without arguments in command", function()
local handler = io.popen("./spec/script foo install 2>&1", "r") local handler = io.popen("./spec/script foo install 2>&1", "r")
assert.equal(table.concat({ assert.equal(table.concat({
"Usage: ./spec/script install [-f <server>] [-h] <rock> [<version>]", "Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]",
"", "",
"Error: too few arguments", "Error: too few arguments",
"" ""
@@ -71,7 +71,7 @@ describe("tests related to CLI behaviour #unsafe", function()
it("generates correct error message and tip in command", function() it("generates correct error message and tip in command", function()
local handler = io.popen("./spec/script foo install bar --form=there 2>&1", "r") local handler = io.popen("./spec/script foo install bar --form=there 2>&1", "r")
assert.equal(table.concat({ assert.equal(table.concat({
"Usage: ./spec/script install [-f <server>] [-h] <rock> [<version>]", "Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]",
"", "",
"Error: unknown option '--form'", "Error: unknown option '--form'",
"Did you mean '--from'?", "Did you mean '--from'?",
@@ -106,7 +106,7 @@ describe("tests related to CLI behaviour #unsafe", function()
it("generates correct help message for command", function() it("generates correct help message for command", function()
local handler = io.popen("./spec/script foo install --help 2>&1", "r") local handler = io.popen("./spec/script foo install --help 2>&1", "r")
assert.equal(table.concat({ assert.equal(table.concat({
"Usage: ./spec/script install [-f <server>] [-h] <rock> [<version>]", "Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]",
"", "",
"Install a rock. ", "Install a rock. ",
"", "",
@@ -115,7 +115,7 @@ describe("tests related to CLI behaviour #unsafe", function()
" version Version of the rock. ", " version Version of the rock. ",
"", "",
"Options: ", "Options: ",
" -f <server>, --from <server>", " -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. ",
"", "",

View File

@@ -36,7 +36,7 @@ describe("tests related to usage message generation", function()
parser:option "--config" parser:option "--config"
assert.equal( assert.equal(
[=[Usage: foo [-q] --from <server> [--config <config>]]=], [=[Usage: foo [-q] --from <from> [--config <config>]]=],
parser:get_usage() parser:get_usage()
) )
end) end)

View File

@@ -306,7 +306,7 @@ function Argument:_get_default_argname()
end end
function Option:_get_default_argname() function Option:_get_default_argname()
return "<" .. (self._target or self:_get_default_target()) .. ">" return "<" .. self:_get_default_target() .. ">"
end end
-- Returns label to be shown in the help message. -- Returns label to be shown in the help message.