mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-27 18:42:20 +00:00
Completions: validate/escape some missed things
This commit is contained in:
@@ -96,7 +96,7 @@ _comptest() {
|
||||
{-h,--help}"[Show this help message and exit]" \
|
||||
"--completion[Output a shell completion script for the specified shell]: :(bash zsh fish)" \
|
||||
"*"{-v,--verbose}"[Set the verbosity level]" \
|
||||
{-f,--files}"[A description with illegal \' characters]:*: :_files" \
|
||||
{-f,--files}"[A description with illegal \"' characters]:*: :_files" \
|
||||
": :_comptest_cmds" \
|
||||
"*:: :->args" \
|
||||
&& return 0
|
||||
@@ -193,7 +193,7 @@ complete -c comptest -n '__fish_use_subcommand' -xa 'admin' -d 'Rock server admi
|
||||
complete -c comptest -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -l completion -xa 'bash zsh fish' -d 'Output a shell completion script for the specified shell'
|
||||
complete -c comptest -s v -l verbose -d 'Set the verbosity level'
|
||||
complete -c comptest -s f -l files -r -d 'A description with illegal \\\' characters'
|
||||
complete -c comptest -s f -l files -r -d 'A description with illegal "\' characters'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from help' -xa 'help completion install i admin'
|
||||
complete -c comptest -n '__fish_seen_subcommand_from help' -s h -l help -d 'Show this help message and exit'
|
||||
|
@@ -12,7 +12,7 @@ parser:flag "-v --verbose"
|
||||
:count "*"
|
||||
|
||||
parser:option "-f --files"
|
||||
:description "A description with illegal \\' characters."
|
||||
:description "A description with illegal \"' characters."
|
||||
:args "+"
|
||||
|
||||
local install = parser:command "install i"
|
||||
|
@@ -1110,6 +1110,15 @@ function Parser:_is_shell_safe()
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, argument in ipairs(self._arguments) do
|
||||
if argument._choices then
|
||||
for _, choice in ipairs(argument._choices) do
|
||||
if choice:find("[%s'\"]") then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, command in ipairs(self._commands) do
|
||||
if not command:_is_shell_safe() then
|
||||
return false
|
||||
@@ -1314,7 +1323,8 @@ function Parser:_zsh_arguments(buf, cmd_name, indent)
|
||||
table.insert(line, option._name)
|
||||
end
|
||||
if option._description then
|
||||
table.insert(line, "[" .. get_short_description(option) .. "]")
|
||||
local description = get_short_description(option):gsub('["%]:]', "\\%0")
|
||||
table.insert(line, "[" .. description .. "]")
|
||||
end
|
||||
if option._maxargs == math.huge then
|
||||
table.insert(line, ":*")
|
||||
@@ -1369,7 +1379,7 @@ function Parser:_zsh_cmds(buf, cmd_name)
|
||||
table.insert(line, '"' .. command._name)
|
||||
end
|
||||
if command._description then
|
||||
table.insert(line, ":" .. get_short_description(command))
|
||||
table.insert(line, ":" .. get_short_description(command):gsub('["]', "\\%0"))
|
||||
end
|
||||
table.insert(buf, " " .. table.concat(line) .. '"')
|
||||
end
|
||||
|
Reference in New Issue
Block a user