mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Fixed - being replaced with _ in custom targets
Default argname for options is now default target in brackets
This commit is contained in:
@@ -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)
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user