forked from monzo/orchestra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
orchestra
65 lines (61 loc) · 2.06 KB
/
orchestra
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
#!/bin/bash
_orchestra_find_projectdir() {
filename="orchestra.yml"
current_dir=$(pwd)
while [ "$current_dir" != "/" ]; do
if [ -f "$current_dir/$filename" ]; then
echo "${current_dir}"
break
fi
current_dir=$(dirname "$current_dir")
done
}
_orchestra_targets_autcomplete() {
projdir=$(_orchestra_find_projectdir)
svcs=$(cd "${projdir}" 2>/dev/null && ls -d -- **/service.* 2>/dev/null)
stacks=$(echo "${svcs}" | cut -d/ -f-1 | sort -u)
echo "${stacks} ${svcs}"
}
_orchestra_bash_autocomplete() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="build export install logs ps restart start stop test help"
targets=$(_orchestra_targets_autcomplete)
case "${COMP_WORDS[1]}" in
build|install|logs|ps|stop)
COMPREPLY=( $(compgen -W "${targets}" -- ${cur}) )
return 0
;;
test)
if [[ "${prev}" == "test" || "${prev}" =~ --* ]]; then
COMPREPLY=( $(compgen -W "--verbose --race" -- ${cur}) )
fi
COMPREPLY+=( $(compgen -W "${targets}" -- ${cur}) )
return 0
;;
start|restart)
if [[ "${prev}" == "start" || "${prev}" == "restart" ]]; then
COMPREPLY=( $(compgen -W "--logs --attach" -- ${cur}) )
fi
COMPREPLY+=( $(compgen -W "${targets}" -- ${cur}) )
return 0
;;
*)
if [[ "${prev}" == "orchestra" ]]; then
COMPREPLY=( $(compgen -W "--help --version --config" -- ${cur}) )
fi
if [[ "${prev}" == "--help" || "${prev}" == "--version" ]]; then
return 0
fi
if [[ "${prev}" == "--config" ]]; then
COMPREPLY=( $(compgen -f -- ${cur}) )
return 0
fi
COMPREPLY+=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
esac
}
complete -F _orchestra_bash_autocomplete orchestra