mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
ZSH completion tried to parse directive from the wrong line (it is available on the second to last line, not last line).
Modify the behavior in completion to remove the last line from output and the directive.
This commit is contained in:
parent
bf6cb5804d
commit
38e7fe9d4f
1 changed files with 12 additions and 8 deletions
|
@ -135,22 +135,26 @@ _%[1]s()
|
|||
out=$(eval ${requestComp} 2>/dev/null)
|
||||
__%[1]s_debug "completion output: ${out}"
|
||||
|
||||
# Extract the directive integer following a : from the last line
|
||||
# Extract the directive integer following a :
|
||||
directive=0
|
||||
__kubecm_debug "Extracting directive from the output"
|
||||
local lastLine
|
||||
while IFS='\n' read -r line; do
|
||||
lastLine=${line}
|
||||
done < <(printf "%%s\n" "${out[@]}")
|
||||
__%[1]s_debug "last line: ${lastLine}"
|
||||
|
||||
if [ "${lastLine[1]}" = : ]; then
|
||||
if [ "${#lastLine}" -eq 2 ] && [ "${lastLine[1]}" = : ]; then
|
||||
directive=${lastLine[2,-1]}
|
||||
# Remove the directive including the : and the newline
|
||||
fi
|
||||
done < <(printf "%s\n" "${out[@]}")
|
||||
__kubecm_debug "last line: ${lastLine}"
|
||||
|
||||
# Remove the last line and directive including the : and the newline
|
||||
if [ $directive -gt 0 ]; then
|
||||
local suffix
|
||||
(( suffix=${#lastLine}+2))
|
||||
(( suffix=${#lastLine}+5))
|
||||
out=${out[1,-$suffix]}
|
||||
else
|
||||
# There is no directive specified. Leave $out as is.
|
||||
__%[1]s_debug "No directive found. Setting do default"
|
||||
__kubecm_debug "No directive found. Setting do default"
|
||||
directive=0
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue