mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-13 21:15:40 +00:00
Allow deleting multiple contexts at once
fixes #39 Example: `kubectx -d ctx1 ctx2`
This commit is contained in:
parent
f986c148b2
commit
4a1d73d5fe
28
kubectx
28
kubectx
@ -26,14 +26,14 @@ KUBECTX="${HOME}/.kube/kubectx"
|
|||||||
usage() {
|
usage() {
|
||||||
cat <<"EOF"
|
cat <<"EOF"
|
||||||
USAGE:
|
USAGE:
|
||||||
kubectx : list the contexts
|
kubectx : list the contexts
|
||||||
kubectx <NAME> : switch to context <NAME>
|
kubectx <NAME> : switch to context <NAME>
|
||||||
kubectx - : switch to the previous context
|
kubectx - : switch to the previous context
|
||||||
kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
|
kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
|
||||||
kubectx <NEW_NAME>=. : rename current-context to <NEW_NAME>
|
kubectx <NEW_NAME>=. : rename current-context to <NEW_NAME>
|
||||||
kubectx -d <NAME> : delete context <NAME> ('.' for current-context)
|
kubectx -d <NAME> [<NAME...>] : delete context <NAME> ('.' for current-context)
|
||||||
(this command won't delete the user/cluster entry
|
(this command won't delete the user/cluster entry
|
||||||
that is used by the context)
|
that is used by the context)
|
||||||
|
|
||||||
kubectx -h,--help : show this message
|
kubectx -h,--help : show this message
|
||||||
EOF
|
EOF
|
||||||
@ -148,6 +148,13 @@ rename_context() {
|
|||||||
kubectl config rename-context "${old_name}" "${new_name}"
|
kubectl config rename-context "${old_name}" "${new_name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_contexts() {
|
||||||
|
IFS=' ' read -ra CTXS <<< "${1}"
|
||||||
|
for i in "${CTXS[@]}"; do
|
||||||
|
delete_context "${i}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
delete_context() {
|
delete_context() {
|
||||||
local ctx
|
local ctx
|
||||||
ctx="${1}"
|
ctx="${1}"
|
||||||
@ -165,11 +172,8 @@ main() {
|
|||||||
if [[ "$#" -lt 2 ]]; then
|
if [[ "$#" -lt 2 ]]; then
|
||||||
echo "error: missing context NAME" >&2
|
echo "error: missing context NAME" >&2
|
||||||
usage
|
usage
|
||||||
elif [[ "$#" -gt 2 ]]; then
|
|
||||||
echo "error: too many arguments" >&2
|
|
||||||
usage
|
|
||||||
fi
|
fi
|
||||||
delete_context "${2}"
|
delete_contexts "${@:2}"
|
||||||
elif [[ "$#" -gt 1 ]]; then
|
elif [[ "$#" -gt 1 ]]; then
|
||||||
echo "error: too many arguments" >&2
|
echo "error: too many arguments" >&2
|
||||||
usage
|
usage
|
||||||
|
Loading…
Reference in New Issue
Block a user