Skip to content

Commit

Permalink
Detect invocation style only in usage() (#183)
Browse files Browse the repository at this point in the history
- removes global SELF variable
- fixes #181

Signed-off-by: Ahmet Alp Balkan <[email protected]>
  • Loading branch information
ahmetb authored Nov 11, 2019
1 parent dcb43fd commit 56e30d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions kubectx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ set -eou pipefail
IFS=$'\n\t'

SELF_CMD="$0"
SELF="kubectx"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ctx"
fi

KUBECTX="${XDG_CACHE_HOME:-$HOME/.kube}/kubectx"

usage() {
local SELF
SELF="kubectx"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ctx"
fi

cat <<EOF
USAGE:
$SELF : list the contexts
Expand Down
10 changes: 6 additions & 4 deletions kubens
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ set -eou pipefail
IFS=$'\n\t'

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"

usage() {
local SELF
SELF="kubens"
if [[ "$(basename "$0")" == kubectl-* ]]; then # invoked as plugin
SELF="kubectl ns"
fi

cat <<EOF
USAGE:
$SELF : list the namespaces in the current context
Expand Down

0 comments on commit 56e30d2

Please sign in to comment.