]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/supervisor/_supervisorctl
d159f20e07f9a384e47e4cc16b78cce80aeeeef6
[dotfiles.git] / zsh / plugins / supervisor / _supervisorctl
1 #compdef supervisorctl
2
3 typeset -A opt_args
4 local context state line
5
6 _supervisorctl() {
7 _arguments -s -S \
8 {--configuration,-c}"[configuration file path (default /etc/supervisor.conf)]:FILENAME:_files" \
9 {--help,-h}"[print usage message and exit]:" \
10 {--interactive,-i}"[start an interactive shell after executing commands]" \
11 {--serverurl,-s}"[URL on which supervisord server is listening (default "http://localhost:9001").]" \
12 {--username,-u}"[username to use for authentication with server]:USERNAME:_users" \
13 {--password,-p}"[password to use for authentication with server]:PASSWORD:" \
14 {--history-file,-r}"[keep a readline history (if readline is available)]:FILENAME:_files" \
15 "*::supervisorctl commands:_supervisorctl_command"
16 }
17
18 (( $+functions[_supervisorctl_command] )) ||
19 _supervisorctl_command() {
20 local cmd ret=1
21
22 (( $+supervisorctl_cmds )) || _supervisorctl_cmds=(
23 "add:Activates any updates in config for process/group" \
24 "avail:Display all configured processes" \
25 "clear:Clear process/multiple-process/all-process log files" \
26 "exit:Exit the supervisor shell." \
27 "fg:Connect to a process in foreground mode" \
28 "maintail:tail of supervisor main log file" \
29 "open:Connect to a remote supervisord process. (for UNIX domain socket, use unix:///socket/path)" \
30 "pid:Get the PID of supervisord." \
31 "quit:Exit the supervisor shell." \
32 "reload:Restart the remote supervisord." \
33 "remove:Removes process/group from active config" \
34 "reread:Reload the daemon's configuration files" \
35 "restart:Restart process or group." \
36 "shutdown:Shut the remote supervisord down." \
37 "start:Start process or groups." \
38 "status:Get process status info." \
39 "stop:Stop process or group." \
40 "tail:tail of process stdout" \
41 "update:Reload config and add/remove as necessary" \
42 "version:Show the version of the remote supervisord process" \
43 "help:Show help" \
44 )
45
46 if (( CURRENT == 1 )); then
47 _describe -t commands 'supervisorctl subcommand' _supervisorctl_cmds \
48 || compadd "$@" - ${(s.:.)${(j.:.)_supervisorctl_syns}}
49 else
50 local curcontext="$curcontext"
51
52 cmd="${${_supervisorctl_cmds[(r)$words[1]:*]%%:*}:-${(k)_supervisorctl_syns[(r)(*:|)$words[1](:*|)]}}"
53 if (( $#cmd )); then
54 curcontext="${curcontext%:*:*}:supervisorctl-${cmd}:"
55 _call_function ret _supervisorctl_$cmd || _message 'no more arguments'
56 else
57 _message "unknown supervisorctl command: $words[1]"
58 fi
59 return ret
60 fi
61 }
62
63 # get supervisor contoroll processes
64 (( $+functions[_get_supervisor_procs] )) ||
65 _get_supervisor_procs() {
66 local cache_policy
67 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
68 if [[ -z "$cache_policy" ]]; then
69 zstyle ":completion:${curcontext}:" cache-policy _supervisor_procs_caching_policy
70 fi
71
72 if ( [[ ${+_supervisor_procs} -eq 0 ]] || _cache_invalid supervisor_procs ) \
73 && ! _retrieve_cache supervisor_procs; then
74
75 _supervisor_procs=(${${(f)"$(supervisorctl status >/dev/null 2>&1 | awk -F' ' '{print $1}')"}})
76 _store_cache supervisor_procs _supervisor_procs
77 fi
78
79 local expl
80 _wanted supervisor_procs expl 'supervisor processes' compadd -a _supervisor_procs
81 }
82
83 _supervisor_procs_caching_policy() {
84 local -a oldp
85 oldp=( "$1"(Nmw+1) )
86 (( $#oldp ))
87 }
88
89 (( $+functions[_supervisorctl_add] )) ||
90 _supervisorctl_add() {
91 _arguments -s \
92 "--help[use help system]" \
93 "*::supervisorctl commands:_supervisorctl"
94 }
95
96 (( $+functions[_supervisorctl_help] )) ||
97 _supervisorctl_help() {
98 _arguments -s \
99 "*:supervisorctl commands:_supervisorctl"
100 }
101
102 (( $+functions[_supervisorctl_maintail] )) ||
103 _supervisorctl_maintail() {
104 _arguments -s \
105 '-f[Continuous tail of supervisor main log file (Ctrl-C to exit)]'
106 }
107
108 (( $+functions[_supervisorctl_start] )) ||
109 _supervisorctl_start() {
110 # TODO: add 'all'
111 _arguments -s \
112 '*::supvervisor process:_get_supervisor_procs'
113 }
114
115 (( $+functions[_supervisorctl_status] )) ||
116 _supervisorctl_status() {
117 _arguments \
118 '*::supvervisor process:_get_supervisor_procs'
119 }
120
121 (( $+functions[_supervisorctl_stop] )) ||
122 _supervisorctl_stop() {
123 # TODO: add 'all'
124 _arguments -s \
125 '*::supvervisor process:_get_supervisor_procs'
126 }
127
128 (( $+functions[_supervisorctl_tail] )) ||
129 _supervisorctl_tail() {
130 # TODO: add 'stderr'
131 _arguments -s \
132 '-f[Continuous tail of named process stdout Ctrl-C to exit.]' \
133 '*::supvervisor process:_get_supervisor_procs'
134 }
135
136 _supervisorctl "$@"