-
Notifications
You must be signed in to change notification settings - Fork 5
/
completions
139 lines (127 loc) · 4.27 KB
/
completions
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
#!/bin/bash
# Useful info found at http://www.linuxjournal.com/content/more-using-bash-complete-command
MU_CLI_VERSION="1.0.3"
sh -c "docker run --rm --volume /tmp:/tmp semtech/mu-cli:${MU_CLI_VERSION} bash ensure-files.sh &"
# I use variables that start with retval to indicate that they are only used to
# populate the return value for the function whose name is the second part of the
# variable name
retval_get_image_list=""
retval_get_repository_list=()
retval_get_tags_for_image=""
get_image_list() {
retval_get_image_list=""
get_repository_list
for repository_name in $(echo $retval_get_repository_list); do
repo_image_list=$(</tmp/musemtech/$repository_name.images)
retval_get_image_list="$retval_get_image_list $repo_image_list"
done
}
get_repository_list() {
retval_get_repository_list=()
# should be done for each repository name
repository="https://info.mu.semte.ch"
repository_name="${repository//https:\/\/}"
repository_name="${repository_name//http:\/\/}"
retval_get_repository_list+=($repository_name)
}
get_tags_for_image() {
image_name=$1
retval_get_tags_for_image=""
for filename in $(find /tmp/musemtech/ -name "*.$image_name.tags"); do
tags_in_file=$(<$filename)
retval_get_tags_for_image="$retval_get_tags_for_images $tags_in_file"
done
}
mu_complete() {
local cmd="${1##*/}"
local word=${COMP_WORDS[COMP_CWORD]}
local line=${COMP_LINE}
local words=($line) # split line into words
local lastchar="${line: -1}"
local wordcount=${#words[@]}
# echo "Words is ${words[0]},${words[1]},${words[2]},${words[3]},${words[4]} !!"
# echo "Word two is '${words[2]}'"
case ${words[1]} in
project)
case ${words[2]} in
new)
;;
doc)
;;
add)
case ${words[3]} in
service)
if (( COMP_CWORD > 4 )); then
IMAGE=${words[4]}
get_tags_for_image $IMAGE
COMPREPLY=(`compgen -W "$retval_get_tags_for_image" $word`)
else
get_image_list
COMPREPLY=(`compgen -W "$retval_get_image_list" $word`)
fi
;;
*)
COMPREPLY=(`compgen -W "service" $word`)
;;
esac
;;
*)
COMPREPLY=(`compgen -W "new doc add" $word`)
;;
esac
;;
service)
case ${words[2]} in
new)
case ${words[3]} in
ruby)
;;
javascript)
;;
python)
;;
*)
COMPREPLY=(`compgen -W "ruby javascript python" $word`)
;;
esac
;;
snippet)
case ${words[3]} in
compose)
;;
creation)
;;
development)
;;
*)
COMPREPLY=(`compgen -W "compose creation development" $word`)
;;
esac
;;
*)
COMPREPLY=(`compgen -W "new" $word`)
;;
esac
;;
migration)
case ${words[2]} in
new)
;;
*)
COMPREPLY=(`compgen -W "new" $word`)
esac
;;
start)
case ${words[2]} in
dev)
;;
*)
COMPREPLY=(`compgen -W "dev" $word`)
esac
;;
*)
COMPREPLY=(`compgen -W "project service script start logs" $word`)
;;
esac
}
complete -F mu_complete mu