-
Notifications
You must be signed in to change notification settings - Fork 0
/
_kubebuilder_download
36 lines (29 loc) · 1 KB
/
_kubebuilder_download
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
#compdef kubebuilder_download
_versions_cache_policy() {
# rebuild if cache is more than a day old
local -a oldp
oldp=( "$1"(mh+1) )
(( $#oldp ))
}
_kubebuilder_download() {
local update_policy ret=1
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
if [[ -z "$update_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy _versions_cache_policy
fi
_cached_versions="kubebuilder_versions"
if _cache_invalid $_cached_versions || ! _retrieve_cache $_cached_versions; then
_versions=(${(@s:\n:)$(curl -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases | jq '.[].tag_name' -r)})
if [ $? -eq 0 ]; then
_store_cache $_cached_versions _versions
else
# Some error occured, probably network related
_versions=""
fi
else
_retrieve_cache $_cached_versions
fi
_describe -t versions "kubebuilder_versions" _versions
ret=0
}
_kubebuilder_download