Skip to content

Commit

Permalink
Improve autocompletion functionality for 'enabler' command
Browse files Browse the repository at this point in the history
  • Loading branch information
taleksovska committed Mar 19, 2024
1 parent 3db356a commit e16bd69
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 70 deletions.
55 changes: 55 additions & 0 deletions enabler/commands/enabler_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
_enabler_complete() {
local cur_word prev_word commands

# 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"
;;
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"
;;
"enabler kind")
commands="$commands $kind"
;;
"enabler platform")
commands="$commands $platform"
;;
"enabler setup")
commands="$commands $setup"
;;
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
70 changes: 0 additions & 70 deletions enabler/enabler_autocomplete.py

This file was deleted.

0 comments on commit e16bd69

Please sign in to comment.