This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli_bashcomp_func.go
130 lines (113 loc) · 3.24 KB
/
cli_bashcomp_func.go
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
package cli
const (
bashCompletionFunc = `# call oc get $1,
__oc_parse_get()
{
local template
template="{{ range .items }}{{ .metadata.name }} {{ end }}"
local oc_out
if oc_out=$(oc get -o template --template="${template}" "$1" 2>/dev/null); then
COMPREPLY=( $( compgen -W "${oc_out[*]}" -- "$cur" ) )
fi
}
__oc_get_resource()
{
if [[ ${#nouns[@]} -eq 0 ]]; then
return 1
fi
__oc_parse_get ${nouns[${#nouns[@]} -1]}
}
# $1 is the name of the pod we want to get the list of containers inside
__oc_get_containers()
{
local template
template="{{ range .spec.containers }}{{ .name }} {{ end }}"
__debug ${FUNCNAME} "nouns are ${nouns[@]}"
local len="${#nouns[@]}"
if [[ ${len} -ne 1 ]]; then
return
fi
local last=${nouns[${len} -1]}
local oc_out
if oc_out=$(oc get -o template --template="${template}" pods "${last}" 2>/dev/null); then
COMPREPLY=( $( compgen -W "${oc_out[*]}" -- "$cur" ) )
fi
}
# Require both a pod and a container to be specified
__oc_require_pod_and_container()
{
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get pods
return 0
fi;
__oc_get_containers
return 0
}
__custom_func() {
case ${last_command} in
# first arg is the kind according to ValidArgs, second is resource name
oc_get | oc_describe | oc_delete | oc_label | oc_stop | oc_expose | oc_export | oc_patch | oc_annotate | oc_env | oc_edit | oc_volume | oc_scale )
__oc_get_resource
return
;;
# first arg is a pod name
oc_rsh | oc_exec)
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get pods
fi;
return
;;
# first arg is a pod name, second is a container name
oc_logs | oc_attach)
__oc_require_pod_and_container
return
;;
# args other than the first are filenames
oc_secrets_new)
# Complete args other than the first as filenames
if [[ ${#nouns[@]} -gt 0 ]]; then
_filedir
fi;
return
;;
# first arg is a build config name
oc_start-build | oc_cancel-build)
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get buildconfigs
fi;
return
;;
# first arg is a deployment config
oc_deploy)
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get deploymentconfigs
fi;
return
;;
# first arg is a deployment config OR deployment
oc_rollback)
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get deploymentconfigs,replicationcontrollers
fi;
return
;;
# first arg is a project name
oc_project)
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get projects
fi;
return
;;
# first arg is an image stream
oc_import-image)
if [[ ${#nouns[@]} -eq 0 ]]; then
__oc_parse_get imagestreams
fi;
return
;;
*)
;;
esac
}
`
)