-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from keitaroinc/feature-add-autocomplete
Add auto-complete for all commands of enabler
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |