mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Zsh completions: complete positional arguments
- Completes choices is they exist, otherwise calls _files - Supports repeated arguments
This commit is contained in:
@@ -1080,6 +1080,7 @@ function Parser:add_help_command(value)
|
|||||||
help "help"
|
help "help"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
help._is_help_command = true
|
||||||
self._help_command = help
|
self._help_command = help
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -1318,10 +1319,31 @@ function Parser:_zsh_arguments(buf, cmd_name, indent)
|
|||||||
table.insert(buf, (" "):rep(indent + 2) .. table.concat(line) .. " \\")
|
table.insert(buf, (" "):rep(indent + 2) .. table.concat(line) .. " \\")
|
||||||
end
|
end
|
||||||
|
|
||||||
if #self._commands > 0 then
|
if self._is_help_command then
|
||||||
table.insert(buf, (" "):rep(indent + 2) .. '": :_' .. cmd_name .. '_cmds" \\')
|
table.insert(buf, (" "):rep(indent + 2) .. '": :(' .. get_commands(self._parent) .. ')" \\')
|
||||||
table.insert(buf, (" "):rep(indent + 2) .. '"*:: :->args" \\')
|
else
|
||||||
|
for _, argument in ipairs(self._arguments) do
|
||||||
|
local spec
|
||||||
|
if argument._choices then
|
||||||
|
spec = ": :(" .. table.concat(argument._choices, " ") .. ")"
|
||||||
|
else
|
||||||
|
spec = ": :_files"
|
||||||
|
end
|
||||||
|
if argument._maxargs == math.huge then
|
||||||
|
table.insert(buf, (" "):rep(indent + 2) .. '"*' .. spec .. '" \\')
|
||||||
|
break
|
||||||
|
end
|
||||||
|
for _ = 1, argument._maxargs do
|
||||||
|
table.insert(buf, (" "):rep(indent + 2) .. '"' .. spec .. '" \\')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #self._commands > 0 then
|
||||||
|
table.insert(buf, (" "):rep(indent + 2) .. '": :_' .. cmd_name .. '_cmds" \\')
|
||||||
|
table.insert(buf, (" "):rep(indent + 2) .. '"*:: :->args" \\')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(buf, (" "):rep(indent + 2) .. "&& return 0")
|
table.insert(buf, (" "):rep(indent + 2) .. "&& return 0")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user