mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-05 19:21:37 +00:00
Automatically generate bash completions for kubectl
This commit is contained in:
@@ -22,7 +22,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
kube::golang::setup_env
|
||||
"${KUBE_ROOT}/hack/build-go.sh" cmd/gendocs cmd/genman
|
||||
"${KUBE_ROOT}/hack/build-go.sh" cmd/gendocs cmd/genman cmd/genbashcomp
|
||||
|
||||
# Get the absolute path of the directory component of a file, i.e. the
|
||||
# absolute path of the dirname of $1.
|
||||
@@ -81,12 +81,19 @@ locations=(
|
||||
)
|
||||
genman=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 )
|
||||
|
||||
if [[ ! -x "$gendocs" || ! -x "$genman" ]]; then
|
||||
locations=(
|
||||
"${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/genbashcomp"
|
||||
"${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/genbashcomp"
|
||||
"${KUBE_ROOT}/platforms/${host_os}/${host_arch}/genbashcomp"
|
||||
)
|
||||
genbashcomp=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 )
|
||||
|
||||
if [[ ! -x "$gendocs" || ! -x "$genman" || ! -x "$genbashcomp" ]]; then
|
||||
{
|
||||
echo "It looks as if you don't have a compiled gendocs or genman binary"
|
||||
echo "It looks as if you don't have a compiled gendocs, genman, or genbashcomp binary"
|
||||
echo
|
||||
echo "If you are running from a clone of the git repo, please run"
|
||||
echo "'./hack/build-go.sh cmd/gendocs cmd/genman'."
|
||||
echo "'./hack/build-go.sh cmd/gendocs cmd/genman cmd/genbashcomp'."
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -109,3 +116,20 @@ else
|
||||
echo "${DOCROOT} is out of date. Please run hack/run-gendocs.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COMPROOT="${KUBE_ROOT}/contrib/completions"
|
||||
TMP_COMPROOT="${KUBE_ROOT}/contrib/completions_tmp"
|
||||
cp -a "${COMPROOT}" "${TMP_COMPROOT}"
|
||||
${genbashcomp} "${TMP_COMPROOT}/bash/"
|
||||
set +e
|
||||
diff -Naupr "${COMPROOT}" "${TMP_COMPROOT}"
|
||||
ret=$?
|
||||
set -e
|
||||
rm -rf ${TMP_COMPROOT}
|
||||
if [ $ret -eq 0 ]
|
||||
then
|
||||
echo "${COMPROOT} up to date."
|
||||
else
|
||||
echo "${COMPROOT} is out of date. Please run hack/run-gendocs.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
Reference in New Issue
Block a user