Browse Source

[Minor] Update bundled lua-argparse to 0.7.1

tags/3.2
Vsevolod Stakhov 2 years ago
parent
commit
b805127041
2 changed files with 31 additions and 9 deletions
  1. 1
    1
      contrib/DEPENDENCY_INFO.md
  2. 30
    8
      contrib/lua-argparse/argparse.lua

+ 1
- 1
contrib/DEPENDENCY_INFO.md View File

| librdns | ? | BSD-2-Clause | YES | | | librdns | ? | BSD-2-Clause | YES | |
| libucl | ? | BSD-2-Clause | YES | | | libucl | ? | BSD-2-Clause | YES | |
| replxx | 6d93360 | BSD-2-Clause | YES | libicu usage | | replxx | 6d93360 | BSD-2-Clause | YES | libicu usage |
| lua-argparse | 0.7.0 | MIT | NO | |
| lua-argparse | 0.7.1 | MIT | NO | |
| lua-bit | 1.0.2 | MIT | YES | build fixes | | lua-bit | 1.0.2 | MIT | YES | build fixes |
| lua-fun | ? | MIT | YES | rspamd text | | lua-fun | ? | MIT | YES | rspamd text |
| lua-lpeg | 1.0 | MIT | YES | rspamd text + alloc| | lua-lpeg | 1.0 | MIT | YES | rspamd text + alloc|

+ 30
- 8
contrib/lua-argparse/argparse.lua View File

for alias in value:gmatch("%S+") do for alias in value:gmatch("%S+") do
self._name = self._name or alias self._name = self._name or alias
table.insert(self._aliases, alias) table.insert(self._aliases, alias)
table.insert(self._public_aliases, alias)
-- If alias contains '_', accept '-' also.
if alias:find("_", 1, true) then
table.insert(self._aliases, (alias:gsub("_", "-")))
end
end end


-- Do not set _name as with other properties. -- Do not set _name as with other properties.
return true return true
end} end}


local multiname_hidden = {"hidden_name", function(self, value)
typecheck("hidden_name", {"string"}, value)

for alias in value:gmatch("%S+") do
table.insert(self._aliases, alias)
if alias:find("_", 1, true) then
table.insert(self._aliases, (alias:gsub("_", "-")))
end
end

return true
end}

local function parse_boundaries(str) local function parse_boundaries(str)
if tonumber(str) then if tonumber(str) then
return tonumber(str), tonumber(str) return tonumber(str), tonumber(str)
}) })


local Command = class({ local Command = class({
_aliases = {}
_aliases = {},
_public_aliases = {}
}, { }, {
args = 3, args = 3,
multiname, multiname,
typechecked("description", "string"), typechecked("description", "string"),
typechecked("epilog", "string"), typechecked("epilog", "string"),
multiname_hidden,
typechecked("summary", "string"), typechecked("summary", "string"),
typechecked("target", "string"), typechecked("target", "string"),
typechecked("usage", "string"), typechecked("usage", "string"),


local Option = class({ local Option = class({
_aliases = {}, _aliases = {},
_public_aliases = {},
_mincount = 0, _mincount = 0,
_overwrite = true _overwrite = true
}, { }, {
typechecked("convert", "function", "table"), typechecked("convert", "function", "table"),
boundaries("args"), boundaries("args"),
boundaries("count"), boundaries("count"),
multiname_hidden,
typechecked("target", "string"), typechecked("target", "string"),
typechecked("defmode", "string"), typechecked("defmode", "string"),
typechecked("show_default", "boolean"), typechecked("show_default", "boolean"),


if #argument_list == 0 then if #argument_list == 0 then
-- Don't put aliases for simple flags like `-h` on different lines. -- Don't put aliases for simple flags like `-h` on different lines.
return {table.concat(self._aliases, ", ")}
return {table.concat(self._public_aliases, ", ")}
end end


local longest_alias_length = -1 local longest_alias_length = -1


for _, alias in ipairs(self._aliases) do
for _, alias in ipairs(self._public_aliases) do
longest_alias_length = math.max(longest_alias_length, #alias) longest_alias_length = math.max(longest_alias_length, #alias)
end end


local argument_list_repr = table.concat(argument_list, " ") local argument_list_repr = table.concat(argument_list, " ")
local lines = {} local lines = {}


for i, alias in ipairs(self._aliases) do
for i, alias in ipairs(self._public_aliases) do
local line = (" "):rep(longest_alias_length - #alias) .. alias .. " " .. argument_list_repr local line = (" "):rep(longest_alias_length - #alias) .. alias .. " " .. argument_list_repr


if i ~= #self._aliases then
if i ~= #self._public_aliases then
line = line .. "," line = line .. ","
end end


end end


function Command:_get_label_lines() function Command:_get_label_lines()
return {table.concat(self._aliases, ", ")}
return {table.concat(self._public_aliases, ", ")}
end end


function Argument:_get_description() function Argument:_get_description()
function Option:_get_default_target() function Option:_get_default_target()
local res local res


for _, alias in ipairs(self._aliases) do
for _, alias in ipairs(self._public_aliases) do
if alias:sub(1, 1) == alias:sub(2, 2) then if alias:sub(1, 1) == alias:sub(2, 2) then
res = alias:sub(3) res = alias:sub(3)
break break


local argparse = {} local argparse = {}


argparse.version = "0.7.0"
argparse.version = "0.7.1"


setmetatable(argparse, {__call = function(_, ...) setmetatable(argparse, {__call = function(_, ...)
return Parser(default_cmdline[0]):add_help(true)(...) return Parser(default_cmdline[0]):add_help(true)(...)

Loading…
Cancel
Save