mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-07-16 08:17:20 +00:00
add unset flag (#187)
* add unset flag * test unsetting selected context * update readme with new unset flag * testdata notes * set a current context * cleanup * omit fixture changes
This commit is contained in:
parent
f48c4198e7
commit
3369d42e2d
@ -31,6 +31,7 @@ USAGE:
|
|||||||
kubectx -d <NAME> : delete context <NAME> ('.' for current-context)
|
kubectx -d <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 -u, --unset : unset the current context
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
8
kubectx
8
kubectx
@ -43,6 +43,7 @@ USAGE:
|
|||||||
$SELF -d <NAME> [<NAME...>] : delete context <NAME> ('.' for current-context)
|
$SELF -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)
|
||||||
|
$SELF -u, --unset : unset the current context
|
||||||
|
|
||||||
$SELF -h,--help : show this message
|
$SELF -h,--help : show this message
|
||||||
EOF
|
EOF
|
||||||
@ -185,6 +186,11 @@ delete_context() {
|
|||||||
$KUBECTL config delete-context "${ctx}"
|
$KUBECTL config delete-context "${ctx}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset_context() {
|
||||||
|
echo "Unsetting current context." >&2
|
||||||
|
$KUBECTL config unset current-context
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if hash kubectl 2>/dev/null; then
|
if hash kubectl 2>/dev/null; then
|
||||||
KUBECTL=kubectl
|
KUBECTL=kubectl
|
||||||
@ -220,6 +226,8 @@ main() {
|
|||||||
# - it does not fail when current-context property is not set
|
# - it does not fail when current-context property is not set
|
||||||
# - it does not return a trailing newline
|
# - it does not return a trailing newline
|
||||||
kubectl config current-context
|
kubectl config current-context
|
||||||
|
elif [[ "${1}" == '-u' || "${1}" == '--unset' ]]; then
|
||||||
|
unset_context
|
||||||
elif [[ "${1}" == '-h' || "${1}" == '--help' ]]; then
|
elif [[ "${1}" == '-h' || "${1}" == '--help' ]]; then
|
||||||
usage
|
usage
|
||||||
elif [[ "${1}" =~ ^-(.*) ]]; then
|
elif [[ "${1}" =~ ^-(.*) ]]; then
|
||||||
|
@ -239,3 +239,16 @@ load common
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[[ "$output" = "user2@cluster1" ]]
|
[[ "$output" = "user2@cluster1" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "unset selected context" {
|
||||||
|
use_config config2
|
||||||
|
|
||||||
|
run ${COMMAND} user1@cluster1
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
run ${COMMAND} -u
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
run ${COMMAND} -c
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user