Detect invocation style only in usage() (#183)

- removes global SELF variable
- fixes #181

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2019-11-11 11:15:48 -08:00 committed by GitHub
parent dcb43fdf1b
commit 56e30d2b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

10
kubectx
View File

@ -22,14 +22,16 @@ set -eou pipefail
IFS=$'\n\t' IFS=$'\n\t'
SELF_CMD="$0" SELF_CMD="$0"
SELF="kubectx"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ctx"
fi
KUBECTX="${XDG_CACHE_HOME:-$HOME/.kube}/kubectx" KUBECTX="${XDG_CACHE_HOME:-$HOME/.kube}/kubectx"
usage() { usage() {
local SELF
SELF="kubectx"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ctx"
fi
cat <<EOF cat <<EOF
USAGE: USAGE:
$SELF : list the contexts $SELF : list the contexts

10
kubens
View File

@ -22,14 +22,16 @@ set -eou pipefail
IFS=$'\n\t' IFS=$'\n\t'
SELF_CMD="$0" SELF_CMD="$0"
SELF="kubens"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ns"
fi
KUBENS_DIR="${XDG_CACHE_HOME:-$HOME/.kube}/kubens" KUBENS_DIR="${XDG_CACHE_HOME:-$HOME/.kube}/kubens"
usage() { usage() {
local SELF
SELF="kubens"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ns"
fi
cat <<EOF cat <<EOF
USAGE: USAGE:
$SELF : list the namespaces in the current context $SELF : list the namespaces in the current context