Unverified Commit b2c7d17f authored by Ruben Suarez Alvarez's avatar Ruben Suarez Alvarez Committed by GitHub

feat(kubectl-helm-minikube): πŸ§‘β€πŸ’» add helm completion (#1080)

* feat(kubectl-helm-minikube): πŸ§‘β€πŸ’» add helm completion

Like **kubectl**, **helm** supports **bash** and **zsh** command completion.

* test(kubectl-helm-minikube): βœ… test helm bash completion

* chore(kubectl-helm-minikube): πŸ”§ update feature version
parent 56233fda
{ {
"id": "kubectl-helm-minikube", "id": "kubectl-helm-minikube",
"version": "1.1.10", "version": "1.2.0",
"name": "Kubectl, Helm, and Minikube", "name": "Kubectl, Helm, and Minikube",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/kubectl-helm-minikube", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/kubectl-helm-minikube",
"description": "Installs latest version of kubectl, Helm, and optionally minikube. Auto-detects latest versions and installs needed dependencies.", "description": "Installs latest version of kubectl, Helm, and optionally minikube. Auto-detects latest versions and installs needed dependencies.",
......
...@@ -311,6 +311,16 @@ if [ ${HELM_VERSION} != "none" ]; then ...@@ -311,6 +311,16 @@ if [ ${HELM_VERSION} != "none" ]; then
echo '(!) Helm installation failed!' echo '(!) Helm installation failed!'
exit 1 exit 1
fi fi
# helm bash completion
helm completion bash > /etc/bash_completion.d/helm
# helm zsh completion
if [ -e "${USERHOME}/.oh-my-zsh" ]; then
mkdir -p "${USERHOME}/.oh-my-zsh/completions"
helm completion zsh > "${USERHOME}/.oh-my-zsh/completions/_helm"
chown -R "${USERNAME}" "${USERHOME}/.oh-my-zsh"
fi
fi fi
# Install Minikube, verify checksum # Install Minikube, verify checksum
......
#!/bin/bash
command=$1
expected=$2
echo -e "Checking completion for command '$command'..."
# Send command as a character stream, followed by two tab characters, into an interactive bash shell.
# Also note the 'y' which responds to the possible Bash question "Display all xxx possibilities? (y or n)".
# Bash produces the autocompletion output on stderr, so redirect that to stdout.
# The sed bit captures the lines between Header and Footer (used as output delimiters).
# The first grep removes the "Display all" message (that is atomatically answered to "y" by the script).
# The last grep filters the output to lines containing the expected result.
COMPLETE_OUTPUT=$(echo if false\; then "Header"\; $command$'\t'$'\t'y\; "Footer" fi | bash -i 2>&1 | sed -n '/Header/{:a;n;/Footer/q;p;ba}' | grep -v ^'Display all ')
echo -e "\nCompletion output:\n"
echo -e "$COMPLETE_OUTPUT"
echo -e "\n"
FILTERED_COMPLETE_OUTPUT=$(echo "$COMPLETE_OUTPUT" | grep "$expected")
if [ -z "$FILTERED_COMPLETE_OUTPUT" ]; then
echo -e "Completion output does not contains '$expected'."
exit 1
else
echo -e "Completion output contains '$expected'."
exit 0
fi
...@@ -10,5 +10,15 @@ check "kube" kubectl ...@@ -10,5 +10,15 @@ check "kube" kubectl
check "helm" helm version check "helm" helm version
check "minikune" minikube version check "minikune" minikube version
# By default bash complete is disabled for the root user
# Enable it by replacing current ~/.bashrc with the /etc/skel/.bashrc file
mv ~/.bashrc ~/.bashrc.bak
cp /etc/skel/.bashrc ~/
check "helm-bash-completion-contains-version-command" ./checkBashCompletion.sh "helm " "version"
# Restore original ~/.bashrc
mv ~/.bashrc.bak ~/.bashrc
# Report result # Report result
reportResults reportResults
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment