forked from stolostron/cluster-keeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathck
executable file
·65 lines (58 loc) · 1.56 KB
/
ck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# Copyright Contributors to the Open Cluster Management project
set -e -o posix
trap "exit 1" TERM
export TOP_PID=$$
DIR=$(dirname $(readlink $0 || echo $0))
. $DIR/lib/logging.sh
. $DIR/lib/validateDeps.sh
. $DIR/lib/common.sh
SUBCOMMANDS=$(ls $DIR/subcommands)
for subcommand in $SUBCOMMANDS
do
. $DIR/subcommands/$subcommand
done
function usage {
errEcho "usage: $(basename ${0}) [OPTIONS] SUBCOMMAND"
errEcho
errEcho " SUBCOMMAND is one of the following."
errEcho
for subcommandFile in $SUBCOMMANDS
do
local subcommand=$(basename $subcommandFile .sh)
local subcommandFunction=$(echo "$subcommand" | tr '-' '_')
errEcho " $subcommand"
errEcho " $(${subcommandFunction}_description)"
done
errEcho
errEcho " The following OPTIONS are available:"
errEcho
errEcho " -h Display usage for SUBCOMMAND"
errEcho " -v Verbosity level for information printed to stderr. Default: 0"
errEcho
abort
}
while getopts :v:h o
do case "$o" in
h) HELP="true";;
v) VERBOSITY="$OPTARG";;
[?]) usage;;
esac
done
shift $(($OPTIND - 1))
subcommand="$1"
[[ -n $subcommand && -f $DIR/subcommands/${subcommand}.sh ]] || usage
subcommandFunction=$(echo "$subcommand" | tr '-' '_')
shift
if [[ -n $HELP ]]
then
${subcommandFunction}_usage
else
if [[ -n $KUBECONFIG ]]
then
verbose -1 "WARNING: KUBECONFIG is set and is being ignored by $(basename ${0}) (CLUSTERPOOL_CONTEXT_NAME=${CLUSTERPOOL_CONTEXT_NAME})"
unset KUBECONFIG
fi
verifyContext $CLUSTERPOOL_CONTEXT_NAME
$subcommandFunction "$@"
fi