Debian Codegraph @

bash-completion/hapc

raw
1 #!/bin/bash completion for hapc
2
3 _hapc() {
4 local cur prev cmd_name
5 COMPREPLY=()
6 cur="${COMP_WORDS[COMP_CWORD]}"
7 prev="${COMP_WORDS[COMP_CWORD-1]}"
8 cmd_name="${COMP_WORDS[1]}"
9
10 actions="list-frontends list-backends list-config-backends list-servers list-connections enable-server drain-server stop-server check-safe-to-remove reload-haproxy"
11
12 case "${cmd_name}" in
13 "list-frontends")
14 case ${COMP_CWORD} in
15 2)
16 COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
17 return 0
18 ;;
19 *)
20 return 0
21 ;;
22 esac
23 ;;
24 "list-config-backends")
25 case ${COMP_CWORD} in
26 2)
27 COMPREPLY=( $(compgen -W "--frontend" -- ${cur}) )
28 return 0
29 ;;
30 3)
31 local frontend_list=$(hapc list-frontends)
32 COMPREPLY=( $(compgen -W "${frontend_list}" -- ${cur}) )
33 return 0
34 ;;
35 4)
36 COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
37 return 0
38 ;;
39 *)
40 return 0
41 ;;
42 esac
43 ;;
44 "list-backends")
45 case ${COMP_CWORD} in
46 2)
47 COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
48 return 0
49 ;;
50 *)
51 return 0
52 ;;
53 esac
54 ;;
55 "list-servers")
56 case ${COMP_CWORD} in
57 2)
58 COMPREPLY=( $(compgen -W "--backend" -- ${cur}) )
59 return 0
60 ;;
61 3)
62 local backend_list=$(hapc list-backends | tr \\n " ")
63 COMPREPLY=( $(compgen -W "${backend_list}" -- ${cur}) )
64 return 0
65 ;;
66 4)
67 COMPREPLY=( $(compgen -W "--details --verbose" -- ${cur}) )
68 return 0
69 ;;
70 *)
71 return 0
72 ;;
73 esac
74 ;;
75 "list-connections"|"enable-server"|"drain-server"|"stop-server"|"check-safe-to-remove")
76 case ${COMP_CWORD} in
77 2)
78 COMPREPLY=( $(compgen -W "--backend" -- ${cur}) )
79 return 0
80 ;;
81 3)
82 local backend_list=$(hapc list-backends | tr \\n " ")
83 COMPREPLY=( $(compgen -W "${backend_list}" -- ${cur}) )
84 return 0
85 ;;
86 4)
87 COMPREPLY=( $(compgen -W "--server" -- ${cur}) )
88 return 0
89 ;;
90 5)
91 local servers_list=$(hapc list-servers --backend ${COMP_WORDS[3]} | tr \\n " ")
92 COMPREPLY=( $(compgen -W "${servers_list}" -- ${cur}) )
93 return 0
94 ;;
95 6)
96 if [ "${cmd_name}" = "drain-server" ] ; then
97 COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
98 else
99 COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
100 fi
101 return 0
102 ;;
103 7)
104 if [ "${cmd_name}" = "drain-server" ] ; then
105 COMPREPLY=( $(compgen -W "--wait" -- ${cur}) )
106 fi
107 return 0
108 ;;
109 8)
110 if [ "${cmd_name}" = "drain-server" ] ; then
111 COMPREPLY=( $(compgen -W "--timeout" -- ${cur}) )
112 fi
113 return 0
114 ;;
115 *)
116 return 0
117 ;;
118 esac
119 ;;
120 "reload-haproxy")
121 case ${COMP_CWORD} in
122 2)
123 COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
124 return 0
125 ;;
126 *)
127 return 0
128 ;;
129 esac
130 ;;
131 *)
132 ;;
133 esac
134
135 COMPREPLY=($(compgen -W "${actions}" -- "${cur}"))
136 }
137
138 complete -F _hapc hapc