forked from Gandi/gandi.cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gandi.completion
74 lines (64 loc) · 1.4 KB
/
gandi.completion
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
__gandi_commands()
{
gandi help | egrep '^ [a-z]' | awk '{print $1}' \
| sort -u
}
__gandi_subcommands()
{
local words=$*
[ $1 = "gandi" ] || return
case $2 in
config|api|docker|setup|onewordcmd)
return
;;
deploy)
gandi vhost list | awk '/^name/ {print $3}'
return
;;
esac
$words --help | awk '{print $2}'
}
__gandi_resources()
{
local cmd=$1
case ${COMP_WORDS[$COMP_CWORDS]} in
create|list)
return
;;
*)
;;
esac
case $cmd in
vm)
gandi vm list | awk '/^hostname/ {print $3}'
;;
domain)
gandi domain list
;;
disk)
gandi disk list | awk '/^name/ {print $3}'
;;
oper)
gandi oper list | awk '/^id/ {print $3}'
;;
esac
}
_gandi()
{
local cur=$2 prev=$3
command=${COMP_WORDS[1]}
local IFS=" "$'\n'
case $COMP_CWORD in
1)
COMPREPLY=( $(compgen -W "`__gandi_commands`" -- "$cur") )
;;
2)
COMPREPLY=( $(compgen -W "`__gandi_subcommands ${COMP_WORDS[@]}`" -- \
"$cur" ) )
;;
*)
COMPREPLY=( $(compgen -W "`__gandi_resources $command`" -- "$cur") )
;;
esac
}
complete -F _gandi gandi