summaryrefslogtreecommitdiff
path: root/contrib/leap.bash-completion
blob: 997ac358a83a6247dd41635f2ab342077e085eac (plain)
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
# LEAP CLI BASH COMPLETION
#
# Usage: Add the following line to your ~/.bashrc file.
#
#		source /path/to/leap.bash-completion
# 

# Config
# Where are your leap-cli gems stored?
versions="/var/lib/gems/2.1.0/gems/"

_leap_complete_nodes () {
	nodes="nodes/"
	suffix=".json"

	local items=($(compgen -f $nodes$cur))
	for item in ${items[@]}; do
		item="${item%$suffix}"
		COMPREPLY+=("${item#$nodes}")
	done
}

_leap_complete_tags () {
	tags="tags/"
	suffix=".json"
	local items=($(compgen -f $tags$cur))
	for item in ${items[@]}; do
		item="${item%$suffix}"
		COMPREPLY+=("${item#$tags}")
	done
}

_leap_global_options() {
	COMPREPLY+=($(compgen -W "--color --no-color --debug --force --help --log= --verbose= -v1 -v2 -v3 -v4 -v5 --version --yes" -- ${cur}))
}

_leap_complete_versions () {
	prefix="leap_cli-"

	local items=($(compgen -d $versions$prefix))
	for item in ${items[@]}; do
		item="${item#$versions}"
		# COMPREPLY+=("_${item#$prefix}_")
		COMPREPLY+=($(compgen -W "_${item#$prefix}_" -- ${cur}))
	done
}

_leap()
{
	COMPREPLY=()
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local commands="add-user clean deploy help history inspect list mosh new scp ssh tunnel cert compile db env facts local node test"

	if [[ $COMP_CWORD -gt 1 ]] && [[ "$cur" != -* ]] && [[ "$cur" != _* ]]; then
		local lastarg="${COMP_WORDS[$COMP_CWORD-1]}"

		case "${COMP_WORDS[$COMP_CWORD-1]}" in
			deploy|d)
				_leap_complete_nodes
				_leap_complete_tags
				;;
			mosh)
				_leap_complete_nodes
				;;
			ssh)
				_leap_complete_nodes
				;;
			cert)
				COMPREPLY+=($(compgen -W "ca csr dh update" -- ${cur}))
				;;
			compile|c)
				COMPREPLY+=($(compgen -W "all zone" -- ${cur}))
				;;
			env|e)
				COMPREPLY+=($(compgen -W "ls pin unpin" -- ${cur}))
				;;
			facts)
				COMPREPLY+=($(compgen -W "update" -- ${cur}))
				;;
			local|l)
				COMPREPLY+=($(compgen -W "start stop status save" -- ${cur}))
				;;
			start|stop|status|save)
				_leap_complete_nodes
				;;
			node|n)
				COMPREPLY+=($(compgen -W "add init rm mv" -- ${cur}))
				;;
			add|rm|mv)
				_leap_complete_nodes
				;;
			test|t)
				COMPREPLY+=($(compgen -W "init run" -- ${cur}))
				;;
			init|run)
				_leap_complete_nodes
				;;
			history|h)
				_leap_complete_nodes
				_leap_complete_tags
				;;
			inspect|i)
				_leap_complete_nodes
				_leap_complete_tags
				;;
			help|clean)
				;;
			list|ls)
				_leap_complete_tags
				;;
			leap)
				COMPREPLY+=($(compgen -W "${commands}" -- ${cur}))
				;;
		esac

	else
		if [[ "$cur" == -* ]]; then
			_leap_global_options
		elif [[ "$cur" == _* ]]; then
			_leap_complete_versions
		else 
			COMPREPLY+=($(compgen -W "${commands}" -- ${cur}))
		fi

	fi
}

complete -F _leap leap