Fixed - being replaced with _ in custom targets

Default argname for options is now default target in brackets
This commit is contained in:
mpeterv
2014-08-25 13:44:26 +04:00
parent 6e02b89b9b
commit b02536d6ba
2 changed files with 9 additions and 9 deletions

View File

@@ -191,7 +191,7 @@ describe("tests related to usage message generation", function()
assert.equal(table.concat({ assert.equal(table.concat({
"Usage: foo ([-q] | [-v] | [-i]) ([-l] | [-f <from>])", "Usage: foo ([-q] | [-v] | [-i]) ([-l] | [-f <from>])",
" [--yet-another-option <yet-another-option>]" " [--yet-another-option <yet_another_option>]"
}, "\r\n"), parser:get_usage() }, "\r\n"), 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:_get_target() .. ">" return "<" .. (self._target or self:_get_default_target()) .. ">"
end end
-- Returns label to be shown in the help message. -- Returns label to be shown in the help message.
@@ -359,18 +359,18 @@ function Option:_get_usage()
return usage return usage
end end
function Option:_get_target() function Option:_get_default_target()
if self._target then local res
return self._target
end
for _, alias in ipairs(self._aliases) do for _, alias in ipairs(self._aliases) do
if alias:sub(1, 1) == alias:sub(2, 2) then if alias:sub(1, 1) == alias:sub(2, 2) then
return alias:sub(3) res = alias:sub(3)
break
end end
end end
return self._name:sub(2) res = res or self._name:sub(2)
return (res:gsub("-", "_"))
end end
function Option:_is_vararg() function Option:_is_vararg()
@@ -783,7 +783,7 @@ function Parser:_parse(args, errhandler)
end end
local type_ = option:_get_type() local type_ = option:_get_type()
targets[option] = option:_get_target():gsub("-", "_") targets[option] = option._target or option:_get_default_target()
if type_ == "counter" then if type_ == "counter" then
result[targets[option]] = 0 result[targets[option]] = 0