-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubecall_completion
139 lines (133 loc) · 4.75 KB
/
kubecall_completion
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
function completion_kubecall_main() {
local args
_get_comp_words_by_ref -n = -w args
context_requested=$(kubectl config current-context)
context_names=$(kubectl config get-contexts -o=name | tr "\n" " ")
context_name_array=($context_names)
declare -A kcac_f_and_o
function handle_flag_options() {
if [[ ${args[-1]} == "--context="* ]];then
COMPREPLY=($(compgen -W "$context_names" "${args[-1]#--context=}"))
return 1
elif [[ ${args[-1]} == "--tail="* ]];then
COMPREPLY=($(compgen -W "100 200 500" "${args[-1]#--tail=}"))
return 1
elif [[ ${args[-1]} == -*= ]];then
remove_first_index_element
return 1
elif [[ ${args[-1]} == -* ]];then
COMPREPLY=($(compgen -W "--follow --json --tail= -f -i -t -it --context=" "\-${args[-1]#"-"}"))
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 1
fi
return 2
}
function remove_flag_options() {
for i in ${!args[@]}
do
if [[ ${args[i]} == --* ]] && [[ ${args[i]} == *=* ]]; then
old_ifs=$IFS;IFS="=";read -ra options <<< "${args[i]}";IFS=$old_ifs;
if [[ -z ${options[1]} ]]; then
return 0
fi
kcac_f_and_o[${options[0]}]=${args[i]}
unset args[$i]
elif [[ ${args[i]} == -* ]]; then
kcac_f_and_o[${args[$i]}]=${args[$i]}
unset args[$i]
fi
done
args=( "${args[@]}" )
return 2
}
function remove_first_index_element() {
last_removed=${args[1]}
args=("${args[@]:0:1}" "${args[@]:2}")
}
function context_name_options() {
if [[ ${args[1]} == ${args[-1]} ]];then
COMPREPLY=($(compgen -W "$context_names" "${args[1]}"))
remove_first_index_element
else
remove_first_index_element
fi
return
}
function deployment_name_options() {
if [[ ${args[1]} == ${args[-1]} ]];then
if [[ ${!args[@]} > 2 ]];then
remove_first_index_element
return
fi
if [[ ${kcac_f_and_o["--context"]+isset} ]];then
context_requested=${kcac_f_and_o["--context"]#--context=}
fi
COMPREPLY=($(compgen -W "${deployments_map[$context_requested]}" "${args[1]}"))
remove_first_index_element
else
remove_first_index_element
fi
}
function get_options() {
if [[ ${args[1]} == "pods" ]]; then
remove_first_index_element
deployment_name_options
done=$?; if [ $done -lt 2 ]; then return $done; fi
else
COMPREPLY=($(compgen -W "pods deployments" "${args[1]}"))
fi
}
function context_options() {
if [[ ${args[1]} == "switch" ]]; then
remove_first_index_element
context_name_options
elif [[ ${args[1]} == "list" ]] || [[ ${args[1]} == "current" ]];then
remove_first_index_element
else
COMPREPLY=($(compgen -W "current switch list" "${args[1]}"))
remove_first_index_element
fi
}
function describe_options() {
if [[ ${args[1]} == "pod" ]]; then
remove_first_index_element
deployment_name_options
else
COMPREPLY=($(compgen -W "pod" "${args[1]}"))
fi
}
function delete_options() {
if [[ ${args[1]} == "pod" ]]; then
remove_first_index_element
deployment_name_options
else
COMPREPLY=($(compgen -W "pod" "${args[1]}"))
fi
}
handle_flag_options
done=$?; if [ $done -lt 2 ]; then return $done; fi
remove_flag_options
done=$?; if [ $done -lt 2 ]; then return $done; fi
if [[ ${args[1]} == "get" ]]; then
remove_first_index_element
get_options
elif [[ ${args[1]} == "context" ]]; then
remove_first_index_element
context_options
elif [[ ${args[1]} == "describe" ]]; then
remove_first_index_element
describe_options
elif [[ ${args[1]} == "delete" ]]; then
remove_first_index_element
delete_options
elif [[ ${args[1]} == "logs" ]] || [[ ${args[1]} == "port-forward" ]]; then
remove_first_index_element
deployment_name_options
elif [[ ${args[1]} == "exec" ]] || [[ ${args[1]} == "execall" ]]; then
remove_first_index_element
deployment_name_options
else
COMPREPLY=($(compgen -W "context get logs describe delete exec execall port-forward" "${args[1]}"))
fi
}
complete -F completion_kubecall_main kubecall;