-
Notifications
You must be signed in to change notification settings - Fork 4
/
bluemixUtility
153 lines (128 loc) · 3.44 KB
/
bluemixUtility
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__wlp_user_dir() {
PRGDIR=`dirname "$SCRIPT"`
WLP_HOME=`cd "$PRGDIR/.." && pwd`
if [ -e "$WLP_HOME/java/java.env" ]
then
. "$WLP_HOME/java/java.env"
fi
if [ -e "$WLP_HOME/etc/default.env" ]
then
. "$WLP_HOME/etc/default.env"
fi
if [ -z "${WLP_USER_DIR}" ]
then
WLP_USER_DIR=${WLP_HOME}/usr
fi
}
_getAllServers() {
__wlp_user_dir
servers=""
if [ -e "$WLP_USER_DIR/servers" ]
then
server_dirs=`\ls $WLP_USER_DIR/servers`
for dir in $server_dirs; do
if [ -d $WLP_USER_DIR/servers/$dir ]; then
servers="$servers $dir"
fi
done
fi
echo $servers
}
__bluemixUtility_servers() {
all_servers=`_getAllServers`
COMPREPLY=( $(compgen -W "${all_servers}" -- ${cur}) )
}
__bluemixUtility_avail_configurations() {
__wlp_user_dir
services=""
if [ -e "$WLP_USER_DIR/shared/config/services" ]
then
server_dirs=`\ls $WLP_USER_DIR/shared/config/services`
for dir in $server_dirs; do
if [ -e $WLP_USER_DIR/shared/config/services/$dir/service.xml ]; then
services="$services $dir"
fi
done
fi
COMPREPLY=( $(compgen -W "${services}" -- ${cur}) )
}
__bluemixUtility_imported_configurations() {
__wlp_user_dir
server_name=$1
imports=""
if [ -e "$WLP_USER_DIR/servers/${server_name}/configDropins/defaults" ]
then
server_dirs=`\ls $WLP_USER_DIR/servers/${server_name}/configDropins/defaults`
for dir in $server_dirs; do
name="${dir%.*}"
imports="$imports $name"
done
fi
COMPREPLY=( $(compgen -W "${imports}" -- ${cur}) )
}
_bluemixUtility_unbind() {
case "$cur" in
*)
local counter="2"
if [ $cword -eq $counter ]; then
__bluemixUtility_servers
elif [ $cword -eq $(($counter + 1)) ]; then
server_name="${words[$counter]}"
__bluemixUtility_imported_configurations "$server_name"
fi
;;
esac
}
_bluemixUtility_bind() {
case "$cur" in
*)
local counter="2"
if [ $cword -eq $counter ]; then
__bluemixUtility_servers
elif [ $cword -eq $(($counter + 1)) ]; then
__bluemixUtility_avail_configurations
fi
;;
esac
}
_bluemixUtility_help() {
case "$cur" in
*)
opts="login switch marketplace createService listServices showService bind import listImports unbind deleteService logout info help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
esac
}
_bluemixUtility() {
COMPREPLY=()
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword
SCRIPT=$1
command="help"
local counter=1
while [ $counter -lt $cword ]; do
case "${words[$counter]}" in
*)
command="${words[$counter]}"
command_pos=$counter
break
;;
esac
(( counter++ ))
done
local completions_func=_bluemixUtility_${command}
declare -F $completions_func >/dev/null && $completions_func
return 0
}
complete -F _bluemixUtility bluemixUtility