File: hapc

package info (click to toggle)
haproxy-cmd 0.0.7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 80 kB
  • sloc: python: 250; sh: 132; makefile: 14
file content (138 lines) | stat: -rw-r--r-- 2,695 bytes parent folder | download | duplicates (2)
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
#!/bin/bash completion for hapc

_hapc() {
	local cur prev cmd_name
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	cmd_name="${COMP_WORDS[1]}"

	actions="list-frontends list-backends list-config-backends list-servers list-connections enable-server drain-server stop-server check-safe-to-remove reload-haproxy"

	case "${cmd_name}" in
	"list-frontends")
		case ${COMP_CWORD} in
		2)
			COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	"list-config-backends")
		case ${COMP_CWORD} in
		2)
			COMPREPLY=( $(compgen -W "--frontend" -- ${cur}) )
			return 0
		;;
		3)
			local frontend_list=$(hapc list-frontends)
			COMPREPLY=( $(compgen -W "${frontend_list}" -- ${cur}) )
			return 0
		;;
		4)
			COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	"list-backends")
		case ${COMP_CWORD} in
		2)
			COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	"list-servers")
		case ${COMP_CWORD} in
		2)
			COMPREPLY=( $(compgen -W "--backend" -- ${cur}) )
			return 0
		;;
		3)
			local backend_list=$(hapc list-backends | tr \\n " ")
			COMPREPLY=( $(compgen -W "${backend_list}" -- ${cur}) )
			return 0
		;;
		4)
			COMPREPLY=( $(compgen -W "--details --verbose" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	"list-connections"|"enable-server"|"drain-server"|"stop-server"|"check-safe-to-remove")
		case ${COMP_CWORD} in
		2)
			COMPREPLY=( $(compgen -W "--backend" -- ${cur}) )
			return 0
		;;
		3)
			local backend_list=$(hapc list-backends | tr \\n " ")
			COMPREPLY=( $(compgen -W "${backend_list}" -- ${cur}) )
			return 0
		;;
		4)
			COMPREPLY=( $(compgen -W "--server" -- ${cur}) )
			return 0
		;;
		5)
			local servers_list=$(hapc list-servers --backend ${COMP_WORDS[3]} | tr \\n " ")
			COMPREPLY=( $(compgen -W "${servers_list}" -- ${cur}) )
			return 0
		;;
		6)
			if [ "${cmd_name}" = "drain-server" ] ; then
				COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			else
				COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			fi
			return 0
		;;
		7)
			if [ "${cmd_name}" = "drain-server" ] ; then
				COMPREPLY=( $(compgen -W "--wait" -- ${cur}) )
			fi
			return 0
		;;
		8)
			if [ "${cmd_name}" = "drain-server" ] ; then
				COMPREPLY=( $(compgen -W "--timeout" -- ${cur}) )
			fi
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	"reload-haproxy")
		case ${COMP_CWORD} in
		2)
			COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	*)
	;;
	esac

	COMPREPLY=($(compgen -W "${actions}" -- "${cur}"))
}

complete -F _hapc hapc