Skip to content

Commit

Permalink
Bug fix in enabler_complete function
Browse files Browse the repository at this point in the history
  • Loading branch information
taleksovska committed Mar 25, 2024
1 parent 10bb09f commit 3fa43de
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions enabler/commands/enabler_completion.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,30 @@
_enabler_complete() {
local cur_word prev_word commands
local cur_word prev_word

# Get the current and previous words
cur_word="${COMP_WORDS[COMP_CWORD]}"
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
local categories="apps kind preflight platform setup version"

case "$prev_word" in
"enabler") # noqa
commands="$categories"
COMPREPLY=( $(compgen -W "apps kind preflight platform setup version" -- "$cur_word") )
;;
esac

# Initialize the variable to store previous words
prev_words=""
local apps="namespace"
local kind="create delete status start stop"
local platform="init info keys release version"
local setup="init metallb istio"

# Loop through previous words and concatenate them
for ((i=1; i<COMP_CWORD; i++));
do
prev_words="${prev_words}${COMP_WORDS[i]} "
done

# Trim any trailing whitespace
prev_words="${prev_words% }"

case "$prev_words" in
"enabler apps")
commands="$commands $apps"
"apps")
COMPREPLY=( $(compgen -W "namespace" -- "$cur_word") )
;;
"platform")
COMPREPLY=( $(compgen -W "init info keys release version" -- "$cur_word") )
;;
"enabler kind")
commands="$commands $kind"
"kind")
COMPREPLY=( $(compgen -W "create delete status start stop" -- "$cur_word") )
;;
"enabler platform")
commands="$commands $platform"
"setup")
COMPREPLY=( $(compgen -W "init metallb istio" -- "$cur_word") )
;;
"enabler setup")
commands="$commands $setup"
*)
COMPREPLY=()
;;
esac

echo ""
echo "$commands"

if [[ "$cur_word" == "$prev_word"* ]]; then
COMPREPLY=( $(compgen -W "$commands" -- "$cur_word") )
fi
}

# Register _enabler_complete to provide completion for the enabler command
complete -F _enabler_complete enabler

0 comments on commit 3fa43de

Please sign in to comment.