forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_bashcomp_func.go
75 lines (68 loc) · 1.68 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
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
oc_get | oc_describe | oc_delete)
__oc_get_resource
return
;;
oc_log)
__oc_require_pod_and_container
return
;;
oc_secrets_new)
# Complete args other than the first as filenames
if [[ ${#nouns[@]} -gt 0 ]]; then
_filedir
fi;
return
;;
*)
;;
esac
}
`
)