zsh completion: --container is not mutually exclusive with --host
[pcp.git] / src / zshrc / _pcp
blob35a5d7221b5dc0df257771e571726ff476ba5760
1 #compdef pcp pmafm pmchart pmclient pmclient_fg=pmclient pmdbg pmdiff pmdumplog pmdumptext pmerr pmfind pmie pmie2col pminfo pmiostat pmlogcheck pmlogger pmloglabel pmlogsummary pmprobe pmrep pmstat pmstore pmval
3 # PCP <http://pcp.io> completions for zsh <http://zsh.sf.net>.
5 # Started by Marko Myllynen <myllynen@redhat.com> 2016.
7 # Configuration:
9 #  * PCP offers a *lot* of metrics, hence something like 'pminfo <tab>'
10 #    returns a lot of possible completions. If you wish to complete
11 #    metrics piecewise instead of using their complete names (meaning
12 #    that 'pminfo me<tab>' will offer only 'mem.' not all the metrics
13 #    under 'mem'), this can be enabled with:
15 #      % zstyle ':completion:*:pcp:metrics' full-names off
17 #    In both modes partial word completion is enabled (meaning that when
18 #    completing 'pminfo m.u.f<tab>' it expands to 'pminfo mem.util.free'.
20 #  * Container completion offers by default the names of running
21 #    containers while IDs are also recognized if being completed. To use
22 #    IDs instead of names (but still recognize names, too), set:
24 #      % zstyle ':completion:*:pcp:containers' use-ids on
28 _pcp () {
29   local curcontext="$curcontext" state line expl ret=1
30   local common_help common_most common_pmda arch_req=0
31   typeset -A opt_args
33   local exargs="-? --help -V --version"
34   common_help=(
35     '(- *)'{-\?,--help}'[display help message]'
36     '(- *)'{-V,--version}'[display version number]'
37   )
38   common_most=(
39     "(-a --archive --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-a+,--archive}'[specify metrics source archive]:archive:->archives'
40     "(-h --host -a --archive -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts'
41     "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files'
42     "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]'
43     "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone'
44     "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:'
45     "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:'
46     "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:'
47     "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:'
48     "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:'
49     "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:'
50   )
51   common_pmda=(
52     "(-L --local-PMDA -a --archive -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]'
53     "(-a --archive -h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)'
54   )
56   case $service in
57   pcp)
58     _arguments -A "-*" -C -S -s -w \
59       "$common_help[@]" \
60       "$common_most[@]" \
61       "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
62       "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
63       - set1 \
64       '1:command:->pcp_commands' \
65       - set2 \
66       "(-P --pmie $exargs)"{-P,--pmie}'[display pmie evaluation statistics]' \
67       && return 0
68       # We accept only PCP command options after the first non-option argument
69       # (i.e., the PCP command itself), this makes it so with the -A "-*" above
70       [[ -z $state ]] && state=pcp_cmdopts
71   ;;
72   pmafm)
73     _arguments -A "-*" \
74       '(- *)'{-\?,--help}'[display help message]' \
75       '1:folio:_files' \
76       '2:command:(archives check help hosts list quit remove repeat replay run selections)' \
77       && return 0
78   ;;
79   pmchart)
80     _arguments -C -S -s -w \
81       "$common_help[@]" \
82       "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
83       "(-h --host -H --hostsfile -L --local-PMDA -K --spec-local $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
84       "(-a --archive -L --local-PMDA -K --spec-local $exargs)"\*{-h+,--host}'[specify metrics source host]:host:_hosts' \
85       "(-a --archive -L --local-PMDA -K --spec-local $exargs)"\*{-H+,--hostsfile}'[specify metrics source hosts file]:file:_files' \
86       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
87       "(-a --archive -h --host -H --hostsfile $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
88       "(-L --local-PMDA -a --archive -h --host -H --hostsfile $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
89       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
90       "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
91       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
92       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
93       "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
94       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
95       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
96       "(-c --view $exargs)"\*{-c+,--view}'[specify chart views to load]:file:_files' \
97       "(-C --check $exargs)"{-C,--check}'[check views only]' \
98       "(-F --font-size $exargs)"{-F+,--font-size}'[specify font size]:size:' \
99       "(-f --font-family $exargs)"{-f+,--font-family}'[specify font family]:family:_xft_fonts' \
100       "(-g --geometry $exargs)"{-g+,--geometry}'[specify image geometry (WxH)]:geometry:' \
101       "(-o --output $exargs)"{-o+,--output}'[specify output file]:file:_files' \
102       "(-v --visible $exargs)"{-v+,--visible}'[set points to display]:points:' \
103       "(-W --white $exargs)"{-W,--white}'[export using opaque (white) bg]' \
104       '*:source:_hosts' \
105       && return 0
106   ;;
107   pmclient)
108     _arguments -C -S -s -w \
109       "$common_help[@]" \
110       "$common_most[@]" \
111       "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
112       "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
113       "(-P --pause -h --host $exargs)"{-P,--pause}'[pause between updates in archive mode]' \
114       && return 0
115   ;;
116   pmdbg)
117     _arguments -A "-*" \
118       '(- *)'{-\?,--help}'[display help message]' \
119       '(- *)'{-l,--list}'[list known debug flags]' \
120       '(- *)'-D'[parse name]:name:( $(pmdbg -l | awk "/^DBG_/ {print \$1}" | sed -e "s,DBG_TRACE_,,g") )' \
121       '*:code:( $(pmdbg -l | awk "/^DBG_/ {print \$2}") )' \
122       && return 0
123   ;;
124   pmdiff)
125     _arguments -A "-*" -C -S -s -w \
126       "$common_help[@]" \
127       "(-d --keep $exargs)"{-d,--keep}'[debug, keep temp files]' \
128       "(-p --precision $exargs)"{-p+,--precision}'[set floating point precision]:precision:' \
129       "(-q --threshold $exargs)"{-q+,--threshold}'[specify reporting threshold]:threshold:' \
130       "(--skip-excluded $exargs)"--skip-excluded'[omit excluded metrics info]' \
131       "(--skip-missing $exargs)"--skip-missing'[omit missing metrics info]' \
132       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
133       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
134       "(-B --begin $exargs)"{-B+,--begin}'[set start of second time window]:timespec:' \
135       "(-E --end $exargs)"{-E+,--end}'[set end of time second window]:timespec:' \
136       "(-x  $exargs)"-x+'[define exclude pattern]:regex:' \
137       "(-X  $exargs)"-X+'[specify exclude pattern file]:file:_files' \
138       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
139       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
140       '1:archive:->archives' \
141       '2:archive:->archives' \
142       && return 0
143   ;;
144   pmdumplog)
145     arch_req=1
146     _arguments -A "-*" -C -S -s -w \
147       "$common_help[@]" \
148       - set1 \
149       "(-a --all $exargs)"{-a,--all}'[dump everything]' \
150       "(-d --descs $exargs)"{-d,--descs}'[dump metric descriptions]' \
151       "(-i --insts $exargs)"{-i,--insts}'[dump instance domain descriptions]' \
152       "(-L  $exargs)"-L'[verbose label dump]' \
153       "(-l --label $exargs)"{-l,--label}'[dump archive log label]' \
154       "(-m --metrics $exargs)"{-m,--metrics}'[dump values of metrics]' \
155       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
156       "(-r --reverse $exargs)"{-r,--reverse}'[reverse chronological order]' \
157       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
158       "(-s --sizes $exargs)"{-s,--sizes}'[report data record sizes]' \
159       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
160       "(-t $exargs)"-t'[dump temporal index]' \
161       "(-x $exargs)"-x'[include date in timestamps]' \
162       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
163       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
164       '1:archive:->archives' \
165       '*:metric:->metrics' \
166       - set2 \
167       "(-v $exargs)"-v+'[specify log to dump as raw hex]:file:_files' \
168       && return 0
169   ;;
170   pmdumptext)
171     _arguments -C -S -s -w \
172       "$common_help[@]" \
173       "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
174       "(-h --host $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
175       "(-a --archive $exargs)"\*{-h+,--host}'[specify metrics source host]:host:_hosts' \
176       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
177       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
178       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
179       "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:' \
180       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
181       "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
182       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
183       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
184       "(-c --config $exargs)"{-c+,--config}'[specify metrics list file]:file:_files' \
185       "(-C --check $exargs)"{-C,--check}'[check metrics only]' \
186       "(-d --delimiter $exargs)"{-d+,--delimiter}'[set column delimiter]:delimiter:' \
187       "(-f --time-format $exargs)"{-f+,--time-format}'[set time format string]:format:' \
188       "(-F --fixed $exargs)"{-F,--fixed}'[use fixed width values]' \
189       "(-G --scientific $exargs)"{-G,--scientific}'[use scientific format (if shorter)]' \
190       "(-H --headers $exargs)"{-H,--headers}'[show all headers]' \
191       "(-i --interactive $exargs)"{-i,--interactive}'[format output for interactive use]' \
192       "(-l --source $exargs)"{-l,--source}'[show metrics source]' \
193       "(-m --metrics $exargs)"{-m,--metrics}'[show metric names]' \
194       "(-M $exargs)"-M'[show complete metric names]' \
195       "(-N $exargs)"-N'[show normalizing factor]' \
196       "(-o --offset $exargs)"{-o,--offset}'[prefix timestamp with offset]' \
197       "(-P --precision $exargs)"{-P+,--precision}'[set floating point precision]:precision:' \
198       "(-R --repeat $exargs)"{-R+,--repeat}'[set header repeat frequency]:samples:' \
199       "(-r --raw $exargs)"{-r,--raw}'[report raw values]' \
200       "(-U --unavailable $exargs)"{-U+,--unavailable}'[define string for unavailable values]:string:' \
201       "(-u --units $exargs)"{-u,--units}'[show metric units]' \
202       "(-w --width $exargs)"{-w+,--width}'[set column width]:width:' \
203       "(-X --extended $exargs)"{-X,--extended}'[show extended metric names]' \
204       '*:metric:->metrics' \
205       && return 0
206   ;;
207   pmerr)
208     _arguments -A "-*" \
209       '(- *)'{-\?,--help}'[display help message]' \
210       '(- *)'{-l,--list}'[list known debug flags]' \
211       '*:code:( $(pmerr -l | awk "/ PM_ERR_/ {print \$1}") )' \
212       && return 0
213   ;;
214   pmfind)
215     _arguments -C -S -s -w \
216       "$common_help[@]" \
217       "(-m --mechanism $exargs)"{-m+,--mechanism}'[specify service discovery mechanism]:mechanism:->pmfind_mechs' \
218       "(-r --resolve $exargs)"{-r,--resolve}'[resolve addresses]' \
219       "(-s --service $exargs)"{-s+,--service}'[specify service to find]:service:(all pmcd pmproxy pmwebd)' \
220       "(-t --timeout $exargs)"{-t+,--timeout}'[set discovery timeout in seconds]:timeout:' \
221       "(-q --quiet $exargs)"{-q,--quiet}'[quiet mode]' \
222       && return 0
223   ;;
224   pmie)
225     exargs="-? --help"
226     _arguments -C -S -s -w \
227       '(- *)'{-\?,--help}'[display help message]' \
228       "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
229       "(-h --host $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
230       "(-a --archive $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
231       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
232       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
233       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
234       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
235       "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
236       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
237       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
238       "(-C --check $exargs)"{-C,--check}'[check config only]' \
239       "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files' \
240       "(-d --interact $exargs)"{-d,--interact}'[interactive debugging mode]' \
241       "(-f --foreground $exargs)"{-f,--foreground}'[run in foreground]' \
242       "(-j $exargs)"-j+'[specify stomp protocol file]:file:_files' \
243       "(-l --logfile $exargs)"{-l+,--logfile}'[specify log file]:file:_files' \
244       "(-U --username $exargs)"{-U+,--username}'[specify username to run as]:user:_users' \
245       "(-b --buffer $exargs)"{-b,--buffer}'[use line buffered output]' \
246       "(-e --timestamp $exargs)"{-e,--timestamp}'[print timestamps in verbose mode]' \
247       "(-q --quiet $exargs)"{-q,--quiet}'[quiet mode]' \
248       "(-v $exargs)"-v'[verbose mode]' \
249       "(-V --verbose $exargs)"{-V,--verbose}'[more verbose mode]' \
250       "(-W $exargs)"-W'[most verbose mode]' \
251       "(-X --secret-applet -x --secret-agent $exargs)"{-X,--secret-applet}'[run in thin client mode]' \
252       "(-x --secret-agent -X --secret-applet $exargs)"{-x,--secret-agent}'[run in domain agent mode]' \
253       '*:config:_files' \
254       && return 0
255   ;;
256   pmie2col)
257     exargs="-? --help"
258     _arguments -A "-*" -C -S -s -w \
259       '(- *)'{-\?,--help}'[display help message]' \
260       "(-d --delimiter $exargs)"{-d+,--delimiter}'[specify output delimiter character]:delimiter:' \
261       "(-p --precision $exargs)"{-p+,--precision}'[specify output floating point precision]:precision:' \
262       "(-w --width $exargs)"{-w+,--width}'[specify output column width]:width:' \
263       && return 0
264   ;;
265   pminfo)
266     _arguments -C -S -s -w \
267       "$common_help[@]" \
268       "(-a --archive --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
269       "(-h --host -a --archive -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
270       "(--container -a --archive $exargs)"--container+'[specify container to query]:container:->containers' \
271       "(-L --local-PMDA -a --archive -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
272       "(-a --archive -h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
273       "(-n --namespace -N --uniqnames $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
274       "(-N --uniqnames -n --namespace $exargs)"{-N+,--uniqnames}'[specify alt. PMNS with unique PMID names]:pmnsfile:_files' \
275       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
276       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
277       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
278       "(-b --batch $exargs)"{-b+,--batch}'[set fetch batch size]:size:' \
279       "(-d --desc $exargs)"{-d,--desc}'[print metric description]' \
280       "(-f --fetch $exargs)"{-f,--fetch}'[fetch and print metric values]' \
281       "(-F --fetchall $exargs)"{-F,--fetchall}'[fetch and print all metric values]' \
282       "(-m --pmid $exargs)"{-m,--pmid}'[print PMID]' \
283       "(-M --fullpmid $exargs)"{-M,--fullpmid}'[print PMID verbosely]' \
284       "(-t --oneline $exargs)"{-t,--oneline}'[print terse help text]' \
285       "(-T --helptext $exargs)"{-T,--helptext}'[print verbose help text]' \
286       "(-c --derived $exargs)"{-c+,--derived}'[specify derived metrics config]:file:_files' \
287       "(-x --events $exargs)"{-x,--events}'[unpack and report events]' \
288       "(-v --verify $exargs)"{-v,--verify}'[verify mode, report errors only]' \
289       '*:metric:->metrics' \
290       && return 0
291   ;;
292   pmiostat)
293     _arguments -C -S -s -w \
294       "$common_help[@]" \
295       "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
296       "(-a --archive -h --host $exargs)"{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
297       "(-G --aggregate $exargs)"{-G+,--aggregate}'[set method to aggregate device values]:method:(sum avg min max)' \
298       "(-h --host -a --archive -u --no-interpolation $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
299       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
300       "(-P --precision $exargs)"{-P+,--precision}'[set floating point precision]:precision:' \
301       "(-R --regex $exargs)"{-R+,--regex}'[define device matching regex]:regex:' \
302       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
303       "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:' \
304       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
305       "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
306       "(-u --no-interpolation -h --host $exargs)"{-u,--no-interpolation}'[disable interpolation]' \
307       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
308       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
309       "(-x $exargs)"-x+'[set comma-separated extended options]:options:->pmiostat_extopts' \
310       && return 0
311   ;;
312   pmlogcheck)
313     exargs="-? --help"
314     _arguments -A "-*" -C -S -s -w \
315       '(- *)'{-\?,--help}'[display help message]' \
316       "(-l --label $exargs)"{-l,--label}'[print archive label]' \
317       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
318       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
319       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
320       "(-v --verbose $exargs)"{-v,--verbose}'[verbose output]' \
321       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
322       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
323       '1:archive:->archives' \
324       && return 0
325   ;;
326   pmlogger)
327     exargs="-? --help"
328     _arguments -C -S -s -w \
329       '(- *)'{-\?,--help}'[display help message]' \
330       "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files' \
331       "(-C --check $exargs)"{-C,--check}'[check config only]' \
332       "(-h --host -o --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
333       "(-l --log $exargs)"{-l+,--log}'[specify log file]:file:_files' \
334       "(-L --linger $exargs)"{-L,--linger}'[linger even if not logging]' \
335       "(-m --note $exargs)"{-m+,--note}'[define map file note]:note:' \
336       "(-h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
337       "(-o --local-PMDA -h --host $exargs)"{-o,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
338       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
339       "(-p --PID $exargs)"{-p+,--PID}'[specify PID to exit after]:PID:_pids' \
340       "(-P --primary $exargs)"{-P,--primary}'[run as primary logger instance]' \
341       "(-r --report $exargs)"{-r,--report}'[report record sizes]' \
342       "(-s --size $exargs)"{-s+,--size}'[set endsize of archive]:size:' \
343       "(-t --interval $exargs)"{-t+,--interval}'[set logging interval]:interval:' \
344       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
345       "(-U --username $exargs)"{-U+,--username}'[specify username to run as]:user:_users' \
346       "(-v --volsize $exargs)"{-v+,--volsize}'[set log volume size]:size:' \
347       "(-x $exargs)"-x+'[set control file descriptor]:fd:_file_descriptors' \
348       "(-y $exargs)"-y'[use local time not PMCD timezone]' \
349       '1:archive:_files' \
350       && return 0
351   ;;
352   pmloglabel)
353     exargs="-? --help"
354     _arguments -A "-*" -C -S -s -w \
355       '(- *)'-\?'[display help message]' \
356       "(-h --host $exargs)"{-h+,--host}'[set hostname for all files in archive]:hostname:_hosts' \
357       "(-l --label $exargs)"{-l,--label}'[print archive label]' \
358       "(-L $exargs)"-L'[print archive label verbosely]' \
359       "(-p --pid $exargs)"{-p+,--pid}'[set logger PID for all files in archive]:pid:' \
360       "(-s $exargs)"-s'[write label sentinel values for all files in archive]' \
361       "(-v --verbose $exargs)"{-v,--verbose}'[verbose output]' \
362       "(-V --version $exargs)"{-V+,--version}'[set version number for all files in archive]' \
363       "(-Z --timezone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
364       '1:archive:->archives' \
365       && return 0
366   ;;
367   pmlogsummary)
368     arch_req=1
369     _arguments -C -S -s -w \
370       "$common_help[@]" \
371       "(-a --all $exargs)"{-a,--all}'[print all information]' \
372       "(-b -x $exargs)"-b'[print both type time averages]' \
373       "(-B --bins $exargs)"{-B+,--bins}'[set number of bins]:bins:' \
374       "(-f -F $exargs)"-f'[spreadsheet format with tabs]' \
375       "(-F -f $exargs)"-F'[spreadsheet format with commas]' \
376       "(-H --header $exargs)"{-H,--header}'[print header]' \
377       "(-i --mintime $exargs)"{-i,--mintime}'[print time of min value]' \
378       "(-I --maxtime $exargs)"{-I,--maxtime}'[print time of max value]' \
379       "(-l --label $exargs)"{-l,--label}'[print archive label]' \
380       "(-m --minimum $exargs)"{-m,--minimum}'[print minimum value]' \
381       "(-M --maximum $exargs)"{-M,--maximum}'[print maximum value]' \
382       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
383       "(-N -v --verbose --$exargs)"-N'[suppress warnings]' \
384       "(-p --precision $exargs)"{-p+,--precision}'[set floating point precision]:precision:' \
385       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
386       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
387       "(-v --verbose -N $exargs)"{-v,--verbose}'[verbose mode]' \
388       "(-x -b $exargs)"-x'[print stochastic averages only]' \
389       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
390       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
391       '1:archive:->archives' \
392       '*:metric:->metrics' \
393       && return 0
394   ;;
395   pmprobe)
396     exargs="-? --help -d --version"
397     _arguments -C -S -s -w \
398       '(- *)'{-\?,--help}'[display help message]' \
399       '(- *)'{-d,--version}'[display version number]' \
400       "(-a --archive --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
401       "(-h --host -a --archive -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
402       "(--container -a --archive $exargs)"--container+'[specify container to query]:container:->containers' \
403       "(--derived $exargs)"--derived+'[specify derived metrics config]:file:_files' \
404       "(-L --local-PMDA -a --archice -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
405       "(-a --archive -h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
406       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
407       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
408       "(-f --force $exargs)"{-f,--force}'[report all instances]' \
409       "(-I --external -v --values $exargs)"{-I,--external}'[list external instance names]' \
410       "(-i --internal -v --values $exargs)"{-i,--internal}'[list internal instance numbers]' \
411       "(-V --verbose $exargs)"{-V,--verbose}'[report PDU operations]' \
412       "(-v --values -I --external -i --internal $exargs)"{-v,--values}'[report metric values]' \
413       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
414       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
415       '*:metric:->metrics' \
416       && return 0
417   ;;
418   pmrep)
419     _arguments -A "-*" -C -S -s -w \
420       "$common_help[@]" \
421       "$common_most[@]" \
422       "$common_pmda[@]" \
423       "(--archive-folio -a --archive -h --host -L --local-pmda -K --spec-local $exargs)"--archive-folio+'[specify metrics source folio]:folio:_files' \
424       "(--container -a --archive -d --delay -u --no-interpol $exargs)"--container+'[specify container to query]:container:->containers' \
425       "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files' \
426       "(-C --check $exargs)"{-C,--check}'[check config only]' \
427       "(-o --output $exargs)"{-o+,--output}'[set output target]:target:(archive csv stdout zabbix)' \
428       "(-F --output-file $exargs)"{-F+,--output-file}'[specify output file]:file:_files' \
429       "(-e --derived $exargs)"{-e+,--derived}'[derived metrics definitions]:file or formula:_files' \
430       "(-H --no-header $exargs)"{-H,--no-header}'[omit headers]' \
431       "(-U --no-unit-info $exargs)"{-U,--no-unit-info}'[omit unit info]' \
432       "(-G --no-globals $exargs)"{-G,--no-globals}'[omit global metrics]' \
433       "(-p --timestamps $exargs)"{-p,--timestamps}'[print timestamps]' \
434       "(-d --delay --container -h --host -L --local-PMDA -K --spec-local -u --no-interpol $exargs)"{-d,--delay}'[delay between updates in archive mode]' \
435       "(-r --raw $exargs)"{-r,--raw}'[report raw values]' \
436       "(-w --width $exargs)"{-w+,--width}'[set default column width]:width:' \
437       "(-P --precision $exargs)"{-P+,--precision}'[set floating point precision]:precision:' \
438       "(-l --delimiter $exargs)"{-l+,--delimiter}'[set column delimiter]:delimiter:' \
439       "(-x --extended-header $exargs)"{-x,--extended-header}'[print extended header]' \
440       "(-E --repeat $exargs)"{-E+,--repeat}'[set header repeat frequency]:samples:' \
441       "(-f --timestamp-format $exargs)"{-f+,--timestamp-format}'[set time format string]:format:' \
442       "(-u --no-interpol --container -d --delay -h --host -L --local-PMDA -K --spec-local -t --interval $exargs)"{-u,--no-interpol}'[disable interpolation]' \
443       "(-q --count-scale $exargs)"{-q+,--count-scale}'[set default count unit]:scale:->scales_count' \
444       "(-b --space-scale $exargs)"{-b+,--space-scale}'[set default space unit]:scale:->scales_space' \
445       "(-y --time-scale $exargs)"{-y+,--time-scale}'[set default time unit]:scale:->scales_time' \
446       '*:metric:->metrics' \
447       && return 0
448   ;;
449   pmstat)
450     _arguments -C -S -s -w \
451       "$common_help[@]" \
452       "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
453       "(-h --host -H --hostsfile -L --local-PMDA $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
454       "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
455       "(-a --archive -L --local-PMDA $exargs)"\*{-h+,--host}'[specify metrics source host]:host:_hosts' \
456       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
457       "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
458       "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
459       "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
460       "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:' \
461       "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
462       "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
463       "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
464       "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
465       "(-a --archive -L --local-PMDA $exargs)"\*{-H+,--hostsfile}'[specify metrics source hosts file]:file:_files' \
466       "(-L --local-PMDA -a --archive -h --host -H --hostsfile $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
467       "(-l --suffix $exargs)"{-l,--suffix}'[print hostname suffix]' \
468       "(-P --pause -h --host -L --local-pmda $exargs)"{-P,--pause}'[pause between updates in archive mode]' \
469       "(-x --xcpu $exargs)"{-x,--xcpu}'[report extended CPU statistics]' \
470       && return 0
471   ;;
472   pmstore)
473     _arguments -A "-*" -C -S -s -w \
474       "$common_help[@]" \
475       "(-h --host -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
476       "(-L --local-PMDA -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
477       "(-h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
478       "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
479       "(-f --force $exargs)"{-f,--force}'[store value even if unset]' \
480       "($exargs)"{-i+,--insts}'[specify instances to store to]:instances:->instances' \
481       '1:metric:->metrics' \
482       && return 0
483   ;;
484   pmval)
485     _arguments -C -S -s -w \
486       "$common_help[@]" \
487       "$common_most[@]" \
488       "$common_pmda[@]" \
489       "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
490       "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
491       "(--container -a --archive $exargs)"--container+'[specify container to query]:container:->containers' \
492       "(--derived $exargs)"--derived+'[specify derived metrics config]:file:_files' \
493       "(-d --delay --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-d,--delay}'[delay between updates in archive mode]' \
494       "(-f --precision $exargs)"{-f+,--precision}'[set fixed output format precision]:precision:' \
495       "($exargs)"\*{-i+,--instances}'[specify instances to report]:instances:->instances' \
496       "(-r --raw $exargs)"{-r,--raw}'[report raw values]' \
497       "(-U --nointerp -a --archive --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-U+,--nointerp}'[specify uninterp. metrics source archive]:archive:->archives' \
498       "(-v --verbose $exargs)"{-v,--verbose}'[verbose mode]' \
499       "(-w --width $exargs)"{-w+,--width}'[set column width]:width:' \
500       "(-x --filter $exargs)"{-x+,--filter}'[define event filter pattern]:filter:' \
501       '1:metric:->metrics' \
502       && return 0
503   ;;
504   esac
506   case $state in
507   archives)
508     typeset -a archives
509     if [[ $words[-1] == -* || $words[CURRENT] == *, ]]; then
510       archives=( *(-FM) *.index )
511     else
512       archives=( ${words[-1]##*,}*(-FM) ${words[-1]##*,}*.index )
513     fi
514     if [[ $#archives -gt 0 && $archives = *.index* ]]; then
515       _values -s , -w archive ${archives/.index} && ret=0
516     else
517       _wanted archives expl archive _files -/ && ret=0
518     fi
519   ;;
520   containers)
521     typeset -a conts names found
522     conts=( ${(f)"$(pminfo -f containers.state.running)"} )
523     names=( ${(f)"$(pminfo -f containers.name)"} )
524     for cont in $conts; do
525       [[ $cont == *value?1* ]] || continue
526       for c in $names; do
527         if zstyle -t ":completion:${curcontext}:pcp:containers" use-ids; then
528           [[ ${${=cont}[4]} = ${${=c}[4]} ]] && found+=( ${(Q)${${=cont}[4]}/\]} )
529           [[ ${${=cont}[4]} = ${${=c}[4]} && -n $words[-1] ]] && found+=( ${(Q)${=c}[6]} )
530         else
531           [[ ${${=cont}[4]} = ${${=c}[4]} ]] && found+=( ${(Q)${=c}[6]} )
532           [[ ${${=cont}[4]} = ${${=c}[4]} && -n $words[-1] ]] && found+=( ${(Q)${${=cont}[4]}/\]} )
533         fi
534       done
535     done
536     _wanted containers expl container compadd -a found && ret=0
537   ;;
538   instances)
539     local arch=${~opt_args[-a]:-${~opt_args[--archive]}}
540     local a=${arch:+-a}
541     local cont=${~opt_args[--container]}
542     local c=${cont:+--container}
543     local host=${~opt_args[-h]:-${~opt_args[--host]}}
544     local h=${host:+-h}
545     typeset -a metrics insts found
546     if [[ $arch_req -eq 1 ]]; then
547       a=-a
548       arch=$words[2]
549       for (( i = 2; i <= $#words; i++ )); do
550         [[ $words[$i] != -* && -f ${words[$i]}.index ]] && arch=$words[$i]
551       done
552     fi
553     for (( i = 2; i <= $#words; i++ )); do
554       # Find metrics arguments, mishits will be filtered out w/ $2>0
555       [[ $words[$i] == [a-z]* ]] && metrics+=( $words[$i] )
556     done
557     # TODO: Check if feasible to handle quotes ('") / multiple spaces in insts
558     insts=( ${(f)"$(pmprobe $a ${(e)arch} $c ${(e)cont} $h ${(e)host} -I $metrics 2>/dev/null | awk '!/1 PM_IN_NULL$/ && $1~"^[a-z]" && $2>0 {for(i=3;i<=NF;i++)print $i}')"} )
559     insts=( ${(q-)${${(ps:" ":)insts}//\"}} )
560     # TODO: don't duplicate " when doing pmval -i "<TAB>
561     _wanted instances expl instance compadd -Q -P '"' -S '"' -a insts && ret=0
562   ;;
563   metrics)
564     local arch=${~opt_args[-a]:-${~opt_args[--archive]}}
565     local a=${arch:+-a}
566     local cont=${~opt_args[--container]}
567     local c=${cont:+--container}
568     local host=${~opt_args[-h]:-${~opt_args[--host]}}
569     local h=${host:+-h}
570     if [[ $arch_req -eq 1 ]]; then
571       a=-a
572       arch=$words[2]
573       for (( i = 2; i <= $#words; i++ )); do
574         [[ $words[$i] != -* && -f ${words[$i]}.index ]] && arch=$words[$i]
575       done
576     fi
577     # Derived metrics from command line
578     local drvc=${~opt_args[--derived]}
579     typeset -a drvm
580     [[ $service == pminfo ]] && drvc=${drvc:-${~opt_args[-c]}}
581     [[ $service == pmrep ]] && drvc=${drvc:-${~opt_args[-e]}}
582     if [[ -n $drvc && -f ${(e)drvc} ]]; then
583       drvm=( ${=${${(f)"$(<${(e)drvc})"}:#\#*}%%=*} )
584     fi
585     if [[ -n $drvc && $service == pmrep && ! -f $drvc ]]; then
586       drvm=( ${=${(ps:,:)${(Qe)drvc}}%%=*} )
587     fi
588     if [[ $words[CURRENT] != :* ]]; then
589       if zstyle -T ":completion:${curcontext}:pcp:metrics" full-names; then
590         _wanted metrics expl metric compadd -M 'r:|.=* r:|=*' $drvm \
591           $(pminfo $a ${(e)arch} $c ${(e)cont} $h ${(e)host} 2>/dev/null) && ret=0
592       else
593         typeset -a res
594         res=( $(pminfo $a ${(e)arch} $c ${(e)cont} $h ${(e)host} 2>/dev/null) )
595         res+=( $drvm )
596         _wanted metrics expl metric _multi_parts -i . res
597       fi
598     else
599       # pmrep(1) metricset
600       [[ $service == pmrep ]] || return 1
601       local conf=${~opt_args[-c]:-${~opt_args[--config]}}
602       [[ -z $conf ]] && conf=${${(M)${(f)"$(</etc/pcp.conf)"}:#PCP_SYSCONF_DIR=*}##PCP_SYSCONF_DIR=}/pmrep/pmrep.conf
603       typeset -a sets
604       for s in ${(f)"$(<${(e)conf})"}; do
605         [[ $s == \[*\] && $s != \[(global|options)\] ]] && sets+=:${${s/\[}/\]}
606       done
607       _wanted metricsets expl metricset compadd -a sets && ret=0
608     fi
609   ;;
610   pcp_commands)
611     typeset -a cmds
612     cmds=( ${="$(pcp --help 2>&1)"#*Available Commands:} )
613     _wanted commands expl 'pcp command' compadd $cmds && ret=0
614   ;;
615   pcp_cmdopts)
616     local cmd
617     typeset -a cmdopts
618     for (( i = 2; i <= $#words; i++ )); do
619       [[ $words[$i] != -* ]] && cmd=$words[$i] && break
620     done
621     [[ -z $cmd ]] && return 1
622     [[ $cmd == python ]] && _wanted files expl files _files && return 0
623     cmdopts=( ${${${${(M)${=${(f)"$(pcp $cmd --help 2>&1)"}}:#-[-0-9A-Za-z?]*}/,}/=*}/-USR1} )
624     _values -w options $cmdopts && ret=0
625   ;;
626   pmfind_mechs)
627     if compset -P '*,'; then
628       case "$IPREFIX" in
629       *avahi,)
630         _wanted timeout expl timeout compadd -S = timeout && ret=0
631       ;;
632       *probe=*)
633         local -a opts
634         [[ $IPREFIX != *timeout* ]] && opts+=( timeout )
635         [[ $IPREFIX != *maxThreads* ]] && opts+=( maxThreads )
636         [[ $#opts -eq 0 ]] && ret=0
637         [[ $#opts -gt 0 ]] && _wanted options expl option compadd -S = -a opts && ret=0
638       ;;
639       esac
640     else
641       _wanted mechanisms expl mechanism compadd -S '' avahi probe= && ret=0
642     fi
643   ;;
644   pmiostat_extopts)
645     _values -s , 'extended option' dm t h noidle && ret=0
646   ;;
647   scales_count)
648     _values count-scale \
649       "count x 10^-8" "count x 10^-7" "count x 10^-6" "count x 10^-5" \
650       "count x 10^-4" "count x 10^-3" "count x 10^-2" "count x 10^-2" \
651       "count x 10^-1" "count" "count x 10" "count x 10^2" "count x 10^3" \
652       "count x 10^4" "count x 10^5" "count x 10^6" "count x 10^7" && ret=0
653   ;;
654   scales_space)
655     _wanted space-scales expl 'space scale' compadd \
656       -M 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \
657       byte Kbyte KB Mbyte MB Gbyte GB Tbyte TB Pbyte PB Ebyte EB && ret=0
658   ;;
659   scales_time)
660     _values time-scale \
661       nanosec ns microsec us millisec ms sec s minute min hour hr && ret=0
662   ;;
663   esac
665   return ret
668 _pcp "$@"