This file is indexed.

/usr/share/zsh/site-functions/_pcp is in pcp 4.0.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
#compdef pcp pcp2elasticsearch pcp2graphite pcp2influxdb pcp2json pcp2xlsx pcp2xml pcp2zabbix pmafm pmchart pmclient pmclient_fg=pmclient pmdbg pmdiff pmdumplog pmdumptext pmerr pmfind pmie pmie2col pminfo pmiostat pmlogcheck pmlogextract pmlogger pmloglabel pmlogsummary pmprobe pmrep pmstat pmstore pmval
#
# PCP <http://pcp.io> completions for zsh <http://zsh.sf.net>.
#
# Started by Marko Myllynen <myllynen@redhat.com> 2016.
#
# Configuration:
#
#  * PCP offers a *lot* of metrics, hence something like 'pminfo <tab>'
#    returns a lot of possible completions. If you wish to complete
#    metrics piecewise instead of using their complete names (meaning
#    that 'pminfo me<tab>' will offer only 'mem.' not all the metrics
#    under 'mem'), this can be enabled with:
#
#      % zstyle ':completion:*:*:pcp:metrics' full-names off
#
#    In both modes partial word completion is enabled (meaning that when
#    completing 'pminfo m.u.f<tab>' it expands to 'pminfo mem.util.free'.
#
#  * Container completion offers by default the names of running
#    containers while IDs are also recognized if being completed. To use
#    IDs instead of names (but still recognize names, too), set:
#
#      % zstyle ':completion:*:*:pcp:containers' use-ids on
#
#

_pcp () {
  local curcontext="$curcontext" state line expl ret=1
  local common_help common_most common_pmda arch_req=0
  declare -A opt_args

  local -a py_tools
  py_tools=(pcp2elasticsearch pcp2graphite pcp2influxdb pcp2json pcp2xlsx pcp2xml pcp2zabbix pmrep)

  local exargs="-? --help -V --version"
  common_help=(
    '(- *)'{-\?,--help}'[display help message]'
    '(- *)'{-V,--version}'[display version number]'
  )
  common_most=(
    "(--container -h --host -L --local-PMDA -K --spec-local $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives'
    "(-h --host -a --archive -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts'
    "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]'
    "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone'
    "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:'
    "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:'
    "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:'
    "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:'
    "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:'
    "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:'
  )
  common_pmda=(
    "(-L --local-PMDA -a --archive -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]'
    "(-a --archive -h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)'
  )
  common_python=(
    "(--archive-folio --container -h --host -L --local-PMDA -K --spec-local $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives'
    "(--archive-folio -a --archive --container -h --host -L --local-pmda -K --spec-local $exargs)"--archive-folio+'[specify metrics source folio]:folio:_files'
    "(--container -a --archive --archive-folio -d --delay -u --no-interpol $exargs)"--container+'[specify container to query]:container:->containers'
    "(-h --host -a --archive --archive-folio -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts'
    "(--daemonize $exargs)"--daemonize'[daemonize on startup]'
    "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:'
    "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:'
    "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:'
    "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:'
    "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:'
    "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:'
    "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files'
    "(-C --check $exargs)"{-C,--check}'[check config only]'
    "($exargs)"\*{-e+,--derived}'[derived metrics definitions]:file or formula:_files'
    "(-H --no-header $exargs)"{-H,--no-header}'[omit headers]'
    "(-G --no-globals $exargs)"{-G,--no-globals}'[omit global metrics]'
    "(-r --raw -R --raw-prefer $exargs)"{-r,--raw}'[force reporting raw values]'
    "(-R --raw-prefer -r --raw $exargs)"{-R,--raw-prefer}'[prefer reporting raw values]'
    "(-I --ignore-incompat $exargs)"{-I,--ignore-incompat}'[ignore incompatible metrics]'
    "($exargs)"\*{-i+,--instances}'[specify instances to report]:instances:->instances'
    "(-v --omit-flat $exargs)"{-v,--omit-flat}'[omit single-valued metrics]'
    "(-P --precision $exargs)"{-P+,--precision}'[set default floating point precision]:precision:'
    "(-0 --precision-force $exargs)"{-0+,--precision-force}'[set forced floating point precision]:precision:'
    "(-q --count-scale -Q --count-scale-force $exargs)"{-q+,--count-scale}'[set default count unit]:scale:->scales_count'
    "(-Q --count-scale-force -q --count-scale $exargs)"{-Q+,--count-scale-force}'[set forced count unit]:scale:->scales_count'
    "(-b --space-scale -B --space-scale-force $exargs)"{-b+,--space-scale}'[set default space unit]:scale:->scales_space'
    "(-B --space-scale-force -b --space-scale $exargs)"{-B+,--space-scale-force}'[set forced space unit]:scale:->scales_space'
    "(-y --time-scale -Y --time-scale-force $exargs)"{-y+,--time-scale}'[set default time unit]:scale:->scales_time'
    "(-Y --time-scale-force -y --time-scale $exargs)"{-Y+,--time-scale-force}'[set forced time unit]:scale:->scales_time'
  )

  case $service in
  pcp)
    if (( ! $+_cache_pcp_cmds )); then
      _cache_pcp_cmds=( ${="$(pcp --help 2>&1)"#*Available Commands:} )
    fi
    if (( ! $+_cache_pcp_cmdopts )); then
      typeset -gA _cache_pcp_cmdopts
    fi
    _arguments -A "-*" -C -S -s \
      "$common_help[@]" \
      "$common_most[@]" \
      "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
      "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      - set1 \
      '1:command:->pcp_commands' \
      - set2 \
      "(-P --pmie $exargs)"{-P,--pmie}'[display pmie evaluation statistics]' \
      && return 0
      # We accept only PCP command options after the first non-option argument
      # (i.e., the PCP command itself), this makes it so with the -A "-*" above
      [[ -z $state ]] && state=pcp_cmdopts
  ;;
  pcp2elasticsearch)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-g --es-host $exargs)"{-g+,--es-host}'[elasticsearch server]:host:_hosts' \
      "(-x --es-index $exargs)"{-x+,--es-index}'[elasticsearch index]:index:' \
      "(-X --es-hostid $exargs)"{-X+,--es-hostid}'[elasticsearch host-id]:host-id:' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pcp2graphite)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-E --text-port -p --pickle-port -X --pickle-protocol $exargs)"{-E+,--text-port}'[graphite plaintext port]:port:' \
      "(-g --graphite-host $exargs)"{-g+,--graphite-host}'[graphite server]:host:_hosts' \
      "(-p --pickle-port -E --text-port $exargs)"{-p+,--pickle-port}'[graphite pickle port]:port:' \
      "(-x --prefix $exargs)"{-x+,--prefix}'[prefix for metric names]:port:' \
      "(-X --pickle-protocol -E --text-port $exargs)"{-X+,--pickle-protocol}'[pickle protocol version]:protocol:' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pcp2influxdb)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-E --db-pass $exargs)"{-E+,--db-pass}'[password for database]:password:' \
      "(-g --db-server $exargs)"{-g+,--db-server}'[server URL]:url:_urls' \
      "(-U --db-user $exargs)"{-U+,--db-user}'[username for database]:username:_users' \
      "(-x --db-name $exargs)"{-x+,--db-name}'[metrics database name]:database:' \
      "(-X --db-tags $exargs)"{-X+,--db-tags}'[string of tags to add to the metrics]:tags:' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pcp2json)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-f --timestamp-format $exargs)"{-f+,--timestamp-format}'[set time format string]:format:' \
      "(-F --output-file $exargs)"{-F+,--output-file}'[specify output file]:file:_files' \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-x --extended -X --everything $exargs)"{-x,--extended}'[write extended information]' \
      "(-X --everything -x --extended $exargs)"{-X,--everything}'[write everything, incl. internals]' \
      "(-E --exact-types $exargs)"{-E,--exact-types}'[write numbers as number data types]' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pcp2xlsx)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-f --timestamp-format $exargs)"{-f+,--timestamp-format}'[set time format string]:format:' \
      "(-F --output-file $exargs)"{-F+,--output-file}'[specify output file]:file:_files' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pcp2xml)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-f --timestamp-format $exargs)"{-f+,--timestamp-format}'[set time format string]:format:' \
      "(-F --output-file $exargs)"{-F+,--output-file}'[specify output file]:file:_files' \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-x --extended -X --everything $exargs)"{-x,--extended}'[write extended information]' \
      "(-X --everything -x --extended $exargs)"{-X,--everything}'[write everything, incl. internals]' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pcp2zabbix)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-E --zabbix-interval $exargs)"{-E+,--zabbix-interval}'[send interval]:interval:' \
      "(-g --zabbix-server $exargs)"{-g+,--zabbix-server}'[zabbix server]:host:_hosts' \
      "(-p --zabbix-port $exargs)"{-p+,--zabbix-port}'[zabbix port]:port:' \
      "(-x --zabbix-prefix $exargs)"{-x+,--zabbix-prefix}'[prefix for metric names]:prefix:' \
      "(-X --zabbix-host $exargs)"{-X+,--zabbix-host}'[zabbix host-id]:host-id:' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pmafm)
    _arguments -A "-*" \
      '(- *)'{-\?,--help}'[display help message]' \
      '1:folio:_files' \
      '2:command:(archives check help hosts list quit remove repeat replay run selections)' \
      && return 0
  ;;
  pmchart)
    _arguments -C -S -s \
      "$common_help[@]" \
      "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
      "(-h --host -H --hostsfile -L --local-PMDA -K --spec-local $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-a --archive -L --local-PMDA -K --spec-local $exargs)"\*{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-a --archive -L --local-PMDA -K --spec-local $exargs)"\*{-H+,--hostsfile}'[specify metrics source hosts file]:file:_files' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-a --archive -h --host -H --hostsfile $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
      "(-L --local-PMDA -a --archive -h --host -H --hostsfile $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-c --view $exargs)"\*{-c+,--view}'[specify chart views to load]:file:_files' \
      "(-C --check $exargs)"{-C,--check}'[check views only]' \
      "(-F --font-size $exargs)"{-F+,--font-size}'[specify font size]:size:' \
      "(-f --font-family $exargs)"{-f+,--font-family}'[specify font family]:family:_xft_fonts' \
      "(-g --geometry $exargs)"{-g+,--geometry}'[specify image geometry (WxH)]:geometry:' \
      "(-o --output $exargs)"{-o+,--output}'[specify output file]:file:_files' \
      "(-s --samples $exargs)"{-s+,--samples}'[buffer up N points of sample history]:samples:' \
      "(-v --visible $exargs)"{-v+,--visible}'[set points to display]:points:' \
      "(-W --white $exargs)"{-W,--white}'[export using opaque (white) bg]' \
      '*:source:_hosts' \
      && return 0
  ;;
  pmclient)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_most[@]" \
      "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
      "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-P --pause -h --host $exargs)"{-P,--pause}'[pause between updates in archive mode]' \
      && return 0
  ;;
  pmdbg)
    _arguments -A "-*" \
      '(- *)'{-\?,--help}'[display help message]' \
      '(- *)'{-o,--old}'[old and deprecated (bit-field) encodings]' \
      '(- *)'{-l,--list}'[display values and text for all PCP debug options]' \
      '(- *)'-D'[parse name]:name:( $(pmdbg -l -o | awk "/^DBG_/ {print \$1}" | sed -e "s,DBG_TRACE_,,g") )' \
      '*:code:( $(pmdbg -l -o | awk "/^DBG_/ {print \$2}") )' \
      && return 0
  ;;
  pmdiff)
    _arguments -A "-*" -C -S -s \
      "$common_help[@]" \
      "(-d --keep $exargs)"{-d,--keep}'[debug, keep temp files]' \
      "(-p --precision $exargs)"{-p+,--precision}'[set floating point precision]:precision:' \
      "(-q --threshold $exargs)"{-q+,--threshold}'[specify reporting threshold]:threshold:' \
      "(--skip-excluded $exargs)"--skip-excluded'[omit excluded metrics info]' \
      "(--skip-missing $exargs)"--skip-missing'[omit missing metrics info]' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-B --begin $exargs)"{-B+,--begin}'[set start of second time window]:timespec:' \
      "(-E --end $exargs)"{-E+,--end}'[set end of time second window]:timespec:' \
      "(-x $exargs)"-x+'[define exclude pattern]:regex:' \
      "(-X $exargs)"-X+'[specify exclude pattern file]:file:_files' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      '1:archive:->archives' \
      '2:archive:->archives' \
      && return 0
  ;;
  pmdumplog)
    arch_req=1
    _arguments -C -S -s \
      "$common_help[@]" \
      - set1 \
      "(-a --all $exargs)"{-a,--all}'[dump everything]' \
      "(-d --descs $exargs)"{-d,--descs}'[dump metric descriptions]' \
      "(-e --labelsets $exargs)"{-e,--labelsets}'[dump all metric label metadata]' \
      "(-h --helptext $exargs)"{-h,--helptext}'[dump all metric help text]' \
      "(-i --insts $exargs)"{-i,--insts}'[dump instance domain descriptions]' \
      "(-L $exargs)"-L'[verbose label dump]' \
      "(-l --label $exargs)"{-l,--label}'[dump archive log label]' \
      "(-m --metrics $exargs)"{-m,--metrics}'[dump values of metrics]' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-r --reverse $exargs)"{-r,--reverse}'[reverse chronological order]' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-s --sizes $exargs)"{-s,--sizes}'[report data record sizes]' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-t $exargs)"-t'[dump temporal index]' \
      "(-x $exargs)"-x'[include date in timestamps]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      '1:archive:->archives' \
      '*:metric:->metrics' \
      - set2 \
      "(-v $exargs)"-v+'[specify log to dump as raw hex]:file:_files' \
      && return 0
  ;;
  pmdumptext)
    _arguments -C -S -s \
      "$common_help[@]" \
      "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
      "(-h --host $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-h --host -a --archive $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-c --config $exargs)"{-c+,--config}'[specify metrics list file]:file:_files' \
      "(-C --check $exargs)"{-C,--check}'[check metrics only]' \
      "(-d --delimiter $exargs)"{-d+,--delimiter}'[set column delimiter]:delimiter:' \
      "(-f --time-format $exargs)"{-f+,--time-format}'[set time format string]:format:' \
      "(-F --fixed $exargs)"{-F,--fixed}'[use fixed width values]' \
      "(-G --scientific $exargs)"{-G,--scientific}'[use scientific format (if shorter)]' \
      "(-H --headers $exargs)"{-H,--headers}'[show all headers]' \
      "(-i --interactive $exargs)"{-i,--interactive}'[format output for interactive use]' \
      "(-l --source $exargs)"{-l,--source}'[show metrics source]' \
      "(-m --metrics $exargs)"{-m,--metrics}'[show metric names]' \
      "(-M $exargs)"-M'[show complete metric names]' \
      "(-N $exargs)"-N'[show normalizing factor]' \
      "(-o --offset $exargs)"{-o,--offset}'[prefix timestamp with offset]' \
      "(-P --precision $exargs)"{-P+,--precision}'[set floating point precision]:precision:' \
      "(-R --repeat $exargs)"{-R+,--repeat}'[set header repeat frequency]:samples:' \
      "(-r --raw $exargs)"{-r,--raw}'[report raw values]' \
      "(-U --unavailable $exargs)"{-U+,--unavailable}'[define string for unavailable values]:string:' \
      "(-u --units $exargs)"{-u,--units}'[show metric units]' \
      "(-w --width $exargs)"{-w+,--width}'[set column width]:width:' \
      "(-X --extended $exargs)"{-X,--extended}'[show extended metric names]' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pmerr)
    _arguments -A "-*" \
      '(- *)'{-\?,--help}'[display help message]' \
      '(- *)'{-l,--list}'[list known debug flags]' \
      '*:code:( $(pmerr -l | awk "/ PM_ERR_/ {print \$1}") )' \
      && return 0
  ;;
  pmfind)
    _arguments -C -S -s \
      "$common_help[@]" \
      "(-m --mechanism $exargs)"{-m+,--mechanism}'[specify service discovery mechanism]:mechanism:->pmfind_mechs' \
      "(-r --resolve $exargs)"{-r,--resolve}'[resolve addresses]' \
      "(-s --service $exargs)"{-s+,--service}'[specify service to find]:service:(all pmcd pmproxy pmwebd)' \
      "(-t --timeout $exargs)"{-t+,--timeout}'[set discovery timeout in seconds]:timeout:' \
      "(-q --quiet $exargs)"{-q,--quiet}'[quiet mode]' \
      && return 0
  ;;
  pmie)
    exargs="-? --help"
    _arguments -C -S -s \
      '(- *)'{-\?,--help}'[display help message]' \
      "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
      "(-h --host $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-a --archive $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-C --check $exargs)"{-C,--check}'[check config only]' \
      "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files' \
      "(-d --interact $exargs)"{-d,--interact}'[interactive debugging mode]' \
      "(-f --foreground $exargs)"{-f,--foreground}'[run in foreground]' \
      "(-j $exargs)"-j+'[specify stomp protocol file]:file:_files' \
      "(-l --logfile $exargs)"{-l+,--logfile}'[specify log file]:file:_files' \
      "(-U --username $exargs)"{-U+,--username}'[specify username to run as]:user:_users' \
      "(-b --buffer $exargs)"{-b,--buffer}'[use line buffered output]' \
      "(-e --timestamp $exargs)"{-e,--timestamp}'[print timestamps in verbose mode]' \
      "(-q --quiet $exargs)"{-q,--quiet}'[quiet mode]' \
      "(-v $exargs)"-v'[verbose mode]' \
      "(-V --verbose $exargs)"{-V,--verbose}'[more verbose mode]' \
      "(-W $exargs)"-W'[most verbose mode]' \
      "(-X --secret-applet -x --secret-agent $exargs)"{-X,--secret-applet}'[run in thin client mode]' \
      "(-x --secret-agent -X --secret-applet $exargs)"{-x,--secret-agent}'[run in domain agent mode]' \
      '*:config:_files' \
      && return 0
  ;;
  pmie2col)
    exargs="-? --help"
    _arguments -A "-*" -C -S -s \
      '(- *)'{-\?,--help}'[display help message]' \
      "(-d --delimiter $exargs)"{-d+,--delimiter}'[specify output delimiter character]:delimiter:' \
      "(-p --precision $exargs)"{-p+,--precision}'[specify output floating point precision]:precision:' \
      "(-w --width $exargs)"{-w+,--width}'[specify output column width]:width:' \
      && return 0
  ;;
  pminfo)
    _arguments -C -S -s \
      "$common_help[@]" \
      "(--container -h --host -L --local-PMDA -K --spec-local $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-h --host -a --archive -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(--container -a --archive $exargs)"--container+'[specify container to query]:container:->containers' \
      "(-L --local-PMDA -a --archive -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
      "(-a --archive -h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
      "(-n --namespace -N --uniqnames $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-N --uniqnames -n --namespace $exargs)"{-N+,--uniqnames}'[specify alt. PMNS with unique PMID names]:pmnsfile:_files' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-b --batch $exargs)"{-b+,--batch}'[set fetch batch size]:size:' \
      "(-d --desc $exargs)"{-d,--desc}'[print metric description]' \
      "(-f --fetch $exargs)"{-f,--fetch}'[fetch and print metric values]' \
      "(-F --fetchall $exargs)"{-F,--fetchall}'[fetch and print all metric values]' \
      "(-l --labels $exargs)"{-l,--labels}'[print metric value labels]' \
      "(-m --pmid $exargs)"{-m,--pmid}'[print PMID]' \
      "(-M --fullpmid $exargs)"{-M,--fullpmid}'[print PMID verbosely]' \
      "(-t --oneline $exargs)"{-t,--oneline}'[print terse help text]' \
      "(-T --helptext $exargs)"{-T,--helptext}'[print verbose help text]' \
      "(-c --derived $exargs)"{-c+,--derived}'[specify derived metrics config]:file:_files' \
      "(-x --events $exargs)"{-x,--events}'[unpack and report events]' \
      "(-v --verify $exargs)"{-v,--verify}'[verify mode, report errors only]' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pmiostat)
    _arguments -C -S -s \
      "$common_help[@]" \
      "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
      "(-h --host $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-G --aggregate $exargs)"{-G+,--aggregate}'[set method to aggregate device values]:method:(sum avg min max)' \
      "(-h --host -a --archive -u --no-interpolation $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-P --precision $exargs)"{-P+,--precision}'[set floating point precision]:precision:' \
      "(-R --regex $exargs)"{-R+,--regex}'[define device matching regex]:regex:' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
      "(-u --no-interpolation -h --host $exargs)"{-u,--no-interpolation}'[disable interpolation]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-x $exargs)"-x+'[set comma-separated extended options]:options:->pmiostat_extopts' \
      && return 0
  ;;
  pmlogcheck)
    exargs="-? --help"
    _arguments -C -S -s \
      '(- *)'{-\?,--help}'[display help message]' \
      "(-l --label $exargs)"{-l,--label}'[print archive label]' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-v --verbose $exargs)"{-v,--verbose}'[verbose output]' \
      "(-w --nowrap $exargs)"{-w,--nowrap}'[suppress counter wrap warnings]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      '1:archive:->archives' \
      && return 0
  ;;
  pmlogextract)
    exargs="-? --help"
    _arguments -C -S -s \
      '(- *)'{-\?,--help}'[display help message]' \
      "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files' \
      "(-d --desperate $exargs)"{-d,--desperate}'[save output after fatal error]' \
      "(-f --first $exargs)"{-f,--first}'[use timezone from the first (not last) archive]' \
      "(-m --mark $exargs)"{-m,--mark}'[ignore prologue/epilogue and <mark> records between archives]' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-s --samples $exargs)"{-s+,--samples}'[specify number of log records to write]:samples:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-v $exargs)"-v+'[switch log volumes after this many samples]' \
      "(-w $exargs)"-w'[ignore day/month/year]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      '*:archive:->archives' \
      && return 0
  ;;
  pmlogger)
    exargs="-? --help"
    _arguments -C -S -s \
      '(- *)'{-\?,--help}'[display help message]' \
      "(-c --config $exargs)"{-c+,--config}'[specify config file]:file:_files' \
      "(-C --check $exargs)"{-C,--check}'[check config only]' \
      "(-h --host -o --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-H --labelhost $exargs)"{-H+,--labelhost}'[specify hostname label]:label:' \
      "(-l --log $exargs)"{-l+,--log}'[specify log file]:file:_files' \
      "(-L --linger $exargs)"{-L,--linger}'[linger even if not logging]' \
      "(-m --note $exargs)"{-m+,--note}'[define map file note]:note:' \
      "(-h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
      "(-o --local-PMDA -h --host $exargs)"{-o,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-p --PID $exargs)"{-p+,--PID}'[specify PID to exit after]:PID:_pids' \
      "(-P --primary $exargs)"{-P,--primary}'[run as primary logger instance]' \
      "(-r --report $exargs)"{-r,--report}'[report record sizes]' \
      "(-s --size $exargs)"{-s+,--size}'[set endsize of archive]:size:' \
      "(-t --interval $exargs)"{-t+,--interval}'[set logging interval]:interval:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-U --username $exargs)"{-U+,--username}'[specify username to run as]:user:_users' \
      "(-v --volsize $exargs)"{-v+,--volsize}'[set log volume size]:size:' \
      "(-x $exargs)"-x+'[set control file descriptor]:fd:_file_descriptors' \
      "(-y $exargs)"-y'[use local time not PMCD timezone]' \
      '1:archive:_files' \
      && return 0
  ;;
  pmloglabel)
    exargs="-? --help"
    _arguments -C -S -s \
      '(- *)'-\?'[display help message]' \
      "(-h --host $exargs)"{-h+,--host}'[set hostname for all files in archive]:hostname:_hosts' \
      "(-l --label $exargs)"{-l,--label}'[print archive label]' \
      "(-L $exargs)"-L'[print archive label verbosely]' \
      "(-p --pid $exargs)"{-p+,--pid}'[set logger PID for all files in archive]:pid:' \
      "(-s $exargs)"-s'[write label sentinel values for all files in archive]' \
      "(-v --verbose $exargs)"{-v,--verbose}'[verbose output]' \
      "(-V --version $exargs)"{-V+,--version}'[set version number for all files in archive]' \
      "(-Z --timezone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      '1:archive:->archives' \
      && return 0
  ;;
  pmlogsummary)
    arch_req=1
    _arguments -C -S -s \
      "$common_help[@]" \
      "(-a --all $exargs)"{-a,--all}'[print all information]' \
      "(-b -x $exargs)"-b'[print both type time averages]' \
      "(-B --bins $exargs)"{-B+,--bins}'[set number of bins]:bins:' \
      "(-f -F $exargs)"-f'[spreadsheet format with tabs]' \
      "(-F -f $exargs)"-F'[spreadsheet format with commas]' \
      "(-H --header $exargs)"{-H,--header}'[print header]' \
      "(-i --mintime $exargs)"{-i,--mintime}'[print time of min value]' \
      "(-I --maxtime $exargs)"{-I,--maxtime}'[print time of max value]' \
      "(-l --label $exargs)"{-l,--label}'[print archive label]' \
      "(-m --minimum $exargs)"{-m,--minimum}'[print minimum value]' \
      "(-M --maximum $exargs)"{-M,--maximum}'[print maximum value]' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-N -v --verbose --$exargs)"-N'[suppress warnings]' \
      "(-p --precision $exargs)"{-p+,--precision}'[set floating point precision]:precision:' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-v --verbose -N $exargs)"{-v,--verbose}'[verbose mode]' \
      "(-x -b $exargs)"-x'[print stochastic averages only]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      '1:archive:->archives' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pmprobe)
    exargs="-? --help -d --version"
    _arguments -C -S -s \
      '(- *)'{-\?,--help}'[display help message]' \
      '(- *)'{-d,--version}'[display version number]' \
      "(--container -h --host -L --local-PMDA -K --spec-local $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-h --host -a --archive -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(--container -a --archive $exargs)"--container+'[specify container to query]:container:->containers' \
      "(--derived $exargs)"--derived+'[specify derived metrics config]:file:_files' \
      "(-L --local-PMDA -a --archice -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
      "(-a --archive -h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-f --force $exargs)"{-f,--force}'[report all instances]' \
      "(-F --faster $exargs)"{-F,--faster}'[assume metrics are PMNS leaf nodes]' \
      "(-I --external -v --values $exargs)"{-I,--external}'[list external instance names]' \
      "(-i --internal -v --values $exargs)"{-i,--internal}'[list internal instance numbers]' \
      "(-V --verbose $exargs)"{-V,--verbose}'[report PDU operations]' \
      "(-v --values -I --external -i --internal $exargs)"{-v,--values}'[report metric values]' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pmrep)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_most[@]" \
      "$common_pmda[@]" \
      "$common_python[@]" \
      "(-o --output $exargs)"{-o+,--output}'[set output target]:target:(archive csv stdout)' \
      "(-F --output-file $exargs)"{-F+,--output-file}'[specify output file]:file:_files' \
      "(-U --no-unit-info $exargs)"{-U,--no-unit-info}'[omit unit info]' \
      "(-p --timestamps $exargs)"{-p,--timestamps}'[print timestamps]' \
      "(-d --delay --container -h --host -L --local-PMDA -K --spec-local -u --no-interpol $exargs)"{-d,--delay}'[delay between updates in archive mode]' \
      "(-X --colxrow $exargs)"{-X+,--colxrow}'[swap stdout columns and rows using header label]:label:' \
      "(-w --width -W --width-force $exargs)"{-w+,--width}'[set default column width]:width:' \
      "(-W --width-force -w --width $exargs)"{-W+,--width-force}'[forced column width]:width:' \
      "(-l --delimiter $exargs)"{-l+,--delimiter}'[set column delimiter]:delimiter:' \
      "(-j --live-filter $exargs)"{-j,--live-filter}'[perform instance live filtering]' \
      "(-J --rank $exargs)"{-J+,--rank}'[set limit for results of valued instances]' \
      "(-2 --overall-rank -3 --overall-rank-alt -N --predicate $exargs)"{-2,--overall-rank}'[perform overall ranking from archive]' \
      "(-3 --overall-rank-alt -2 --overall-rank -N --predicate $exargs)"{-3,--overall-rank-alt}'[perform overall ranking using pmrep format]' \
      "(-8 --limit-filter -9 --limit-filter-force $exargs)"{-8+,--limit-filter}'[set default limit filter]' \
      "(-9 --limit-filter-force -8 --limit-filter $exargs)"{-9+,--limit-filter-force}'[set forced limit filter]' \
      "(-n --invert-filter $exargs)"{-n,--invert-filter}'[perform ranking before live filtering]' \
      "(-N --predicate -2 --overall-rank -3 --overall-rank-alt $exargs)"{-N+,--predicate}'[specify predicate metric]:metric:->metrics' \
      "(-k --extended-csv $exargs)"{-k,--extended-csv}'[write extended CSV]' \
      "(-x --extended-header $exargs)"{-x,--extended-header}'[print extended header]' \
      "(-E --repeat-header $exargs)"{-E+,--repeat-header}'[set header repeat frequency]:samples:' \
      "(-1 --dynamic-header $exargs)"{-1,--dynamic-header}'[update header dynamically]:samples:' \
      "(-g --separate-header $exargs)"{-g,--separate-header}'[print separate header]' \
      "(-f --timestamp-format $exargs)"{-f+,--timestamp-format}'[set time format string]:format:' \
      "(-u --no-interpol --container -d --delay -h --host -L --local-PMDA -K --spec-local -t --interval $exargs)"{-u,--no-interpol}'[disable interpolation]' \
      '*:metric:->metrics' \
      && return 0
  ;;
  pmstat)
    _arguments -C -S -s \
      "$common_help[@]" \
      "(-A --align $exargs)"{-A+,--align}'[set initial sample time alignment]:timespec:' \
      "(-h --host -H --hostsfile -L --local-PMDA $exargs)"\*{-a+,--archive}'[specify metrics source archive]:archive:->archives' \
      "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
      "(-a --archive -L --local-PMDA $exargs)"\*{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-O --origin $exargs)"{-O+,--origin}'[set initial sample time origin]:timespec:' \
      "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
      "(-S --start $exargs)"{-S+,--start}'[set start of time window]:timespec:' \
      "(-s --samples $exargs)"{-s+,--samples}'[specify number of samples]:samples:' \
      "(-T --finish $exargs)"{-T+,--finish}'[set end of time window]:timespec:' \
      "(-t --interval $exargs)"{-t+,--interval}'[specify sampling interval]:interval:' \
      "(-Z --timezone -z --hostzone $exargs)"{-Z+,--timezone}'[set reporting timezone]:timezone:_time_zone' \
      "(-z --hostzone -Z --timezone $exargs)"{-z,--hostzone}'[use metrics source timezone]' \
      "(-a --archive -L --local-PMDA $exargs)"\*{-H+,--hostsfile}'[specify metrics source hosts file]:file:_files' \
      "(-L --local-PMDA -a --archive -h --host -H --hostsfile $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
      "(-l --suffix $exargs)"{-l,--suffix}'[print hostname suffix]' \
      "(-P --pause -h --host -L --local-pmda $exargs)"{-P,--pause}'[pause between updates in archive mode]' \
      "(-x --xcpu $exargs)"{-x,--xcpu}'[report extended CPU statistics]' \
      && return 0
  ;;
  pmstore)
    _arguments -A "-*" -C -S -s \
      "$common_help[@]" \
      "(-h --host -L --local-PMDA -K --spec-local $exargs)"{-h+,--host}'[specify metrics source host]:host:_hosts' \
      "(-F --fetch $exargs)"{-F,--fetch}'[perform pmFetch after pmStore to confirm value]' \
      "(-L --local-PMDA -h --host $exargs)"{-L,--local-PMDA}'[use local DSO PMDAs as metrics source]' \
      "(-h --host $exargs)"\*{-K+,--spec-local}'[define PMDA spec for local DSO PMDAs]:spec:(add del clear)' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(-F --fetch $exargs)"{-F,--fetch}'[perform pmFetch after pmStore to confirm value]' \
      "(-f --force $exargs)"{-f,--force}'[store value even if unset]' \
      "($exargs)"\*{-i+,--insts}'[specify instances to store to]:instances:->instances' \
      '1:metric:->metrics' \
      && return 0
  ;;
  pmval)
    _arguments -C -S -s \
      "$common_help[@]" \
      "$common_most[@]" \
      "$common_pmda[@]" \
      "(-g --guimode $exargs)"{-g,--guimode}'[GUI mode with new time control]' \
      "(-p --guiport $exargs)"{-p+,--guiport}'[specify existing time control port]:port:' \
      "(-n --namespace $exargs)"{-n+,--namespace}'[specify alternative PMNS]:pmnsfile:_files' \
      "(--container -a --archive -U --nointerp $exargs)"--container+'[specify container to query]:container:->containers' \
      "(--derived $exargs)"--derived+'[specify derived metrics config]:file:_files' \
      "(-d --delay --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-d,--delay}'[delay between updates in archive mode]' \
      "(-f --precision $exargs)"{-f+,--precision}'[set fixed output format precision]:precision:' \
      "($exargs)"\*{-i+,--instances}'[specify instances to report]:instances:->instances' \
      "(-r --raw $exargs)"{-r,--raw}'[report raw values]' \
      "(-a --archive --container -h --host -L --local-PMDA -K --spec-local $exargs)"{-U+,--nointerp}'[specify uninterpolated metrics source archive]:archive:->archives' \
      "(-v --verbose $exargs)"{-v,--verbose}'[verbose mode]' \
      "(-w --width $exargs)"{-w+,--width}'[set column width]:width:' \
      "(-x --filter $exargs)"{-x+,--filter}'[define event filter pattern]:filter:' \
      '1:metric:->metrics' \
      && return 0
  ;;
  esac

  case $state in
  archives)
    local fpat t
    local -a archives
    [[ -n $words[CURRENT] ]] && t=${words[CURRENT]##*,}
    archives=( ${t}*(-FM) ${t}*.meta* )
    if [[ $#archives -gt 0 && $archives == *.meta* ]]; then
      _values -s , -w archive ${archives/.meta*} && ret=0
    else
      compset -P '*,'
      zstyle -s ":completion:${curcontext}:" file-patterns fpat
      if [[ -z "$fpat" ]]; then
        zstyle ":completion:${curcontext}:" file-patterns '%p:globbed-files'
      fi
      _wanted archives expl archive _files -g '*(-F)' && ret=0
    fi
  ;;
  containers)
    local -a conts names found
    conts=( ${(f)"$(pminfo -f containers.state.running)"} )
    names=( ${(f)"$(pminfo -f containers.name)"} )
    for cont in $conts; do
      [[ $cont == *value?1* ]] || continue
      for c in $names; do
        if zstyle -t ":completion:*:${curcontext}:pcp:containers" use-ids; then
          [[ ${${=cont}[4]} == ${${=c}[4]} ]] && found+=( ${(Q)${${=cont}[4]}/\]} )
          [[ ${${=cont}[4]} == ${${=c}[4]} && -n $words[CURRENT] ]] && found+=( ${(Q)${=c}[6]} )
        else
          [[ ${${=cont}[4]} == ${${=c}[4]} ]] && found+=( ${(Q)${=c}[6]} )
          [[ ${${=cont}[4]} == ${${=c}[4]} && -n $words[CURRENT] ]] && found+=( ${(Q)${${=cont}[4]}/\]} )
        fi
      done
    done
    _wanted containers expl container compadd -a found && ret=0
  ;;
  instances)
    local arch=${${~opt_args[-a]:-${~opt_args[--archive]}}/:/,}
    local a=${arch:+-a}
    local cont=${~opt_args[--container]}
    local c=${cont:+--container}
    local host=${~opt_args[-h]:-${~opt_args[--host]}}
    local h=${host:+-h}
    local -a metrics insts found
    local word
    if [[ $arch_req -eq 1 ]]; then
      a=-a
      arch=$words[2]
      for word in ${words:1}; do
        [[ $word != -* && (-f $word.meta || -f $word.meta.xz) ]] && arch=$word
      done
    fi
    for word in ${words:1}; do
      # Find metrics arguments, mishits will be filtered out w/ $2>0
      [[ $word == [a-z]* ]] && metrics+=( $word )
    done
    # TODO: Check if feasible to handle quotes ('") / multiple spaces in insts
    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}')"} )
    insts=( ${(q-)${${(ps:" ":)insts}//\"}} )
    # TODO: don't duplicate " when doing pmval -i "<TAB>
    _wanted instances expl instance compadd -Q -P '"' -S '"' -a insts && ret=0
  ;;
  metrics)
    local arch=${${~opt_args[-a]:-${~opt_args[--archive]}}/:/,}
    local a=${arch:+-a}
    local cont=${~opt_args[--container]}
    local c=${cont:+--container}
    local host=${~opt_args[-h]:-${~opt_args[--host]}}
    local h=${host:+-h}
    local word
    if [[ $arch_req -eq 1 ]]; then
      a=-a
      arch=$words[2]
      for word in ${words:1}; do
        [[ $word != -* && (-f $word.meta || -f $word.meta.xz) ]] && arch=$word
      done
    fi
    # Derived metrics from command line
    local drvc=${~opt_args[--derived]}
    local -a drvm
    [[ $service == pminfo ]] && drvc=${drvc:-${~opt_args[-c]}}
    (( ${(k)py_tools[(I)$service]} > 0 )) && drvc=${drvc:-${~opt_args[-e]}}
    if [[ -n $drvc && -f ${(e)drvc} ]]; then
      drvm=( ${=${${(f)"$(<${(e)drvc})"}:#\#*}%%=*} )
    fi
    if [[ -n $drvc && (( ${(k)py_tools[(I)$service]} > 0 )) && ! -f $drvc ]]; then
      drvm=( ${=${(ps:,:)${(Qe)drvc}}%%=*} )
    fi
    if [[ $words[CURRENT] != :* ]]; then
      if zstyle -T ":completion:*:${curcontext}:pcp:metrics" full-names; then
        _wanted metrics expl metric compadd -M 'r:|.=* r:|=*' $drvm \
          $(pminfo -d $a ${(e)arch} $c ${(e)cont} $h ${(e)host} 2>/dev/null | grep -Ev '( |^$|^event)') && ret=0
      else
        local -a res
        res=( $(pminfo -d $a ${(e)arch} $c ${(e)cont} $h ${(e)host} 2>/dev/null | grep -Ev '( |^$|^event)') )
        res+=( $drvm )
        _wanted metrics expl metric _multi_parts -i . res
      fi
    else
      # pmrep(1) style metricset
      (( ${(k)py_tools[(I)$service]} > 0 )) || return 1
      local conf=${~opt_args[-c]:-${~opt_args[--config]}}
      if [[ -z $conf ]]; then
        for f in ./$service.conf $HOME/.$service.conf $HOME/.pcp/$service.conf ${${(M)${(f)"$(</etc/pcp.conf)"}:#PCP_SYSCONF_DIR=*}##PCP_SYSCONF_DIR=}/$service/$service.conf; do
          [[ -f $f ]] && conf=$f && break
        done
      fi
      [[ -z $conf ]] && return 1
      local -a sets
      for s in ${(f)"$(<${(e)conf})"}; do
        [[ $s == \[*\] && $s != \[(global|options)\] ]] && sets+=:${${s/\[}/\]}
      done
      _wanted metricsets expl metricset compadd -a sets && ret=0
    fi
  ;;
  pcp_commands)
    _wanted commands expl 'pcp command' compadd -a _cache_pcp_cmds && ret=0
  ;;
  pcp_cmdopts)
    local cmd word
    for word in ${words:1}; do
      [[ -n "${_cache_pcp_cmds[(r)$word]}" ]] && cmd=$word && break
    done
    [[ -z $cmd ]] && return 1
    [[ $cmd == python ]] && _default && return 0
    if [[ -z $_cache_pcp_cmdopts[$cmd] ]]; then
      _cache_pcp_cmdopts[$cmd]=${${${${(M)${=${(f)"$(pcp $cmd --help 2>&1)"}}:#-[-0-9A-Za-z?]*}/,}/=*}/-USR1}
    fi
    [[ -n $_cache_pcp_cmdopts[$cmd] ]] && _values -w option ${(u)=_cache_pcp_cmdopts[$cmd]} && ret=0
  ;;
  pmfind_mechs)
    if compset -P '*,'; then
      case "$IPREFIX" in
      *avahi,)
        _wanted timeout expl timeout compadd -S = timeout && ret=0
      ;;
      *probe=*)
        local -a opts
        [[ $IPREFIX != *timeout* ]] && opts+=( timeout )
        [[ $IPREFIX != *maxThreads* ]] && opts+=( maxThreads )
        [[ $#opts -eq 0 ]] && ret=0
        [[ $#opts -gt 0 ]] && _wanted options expl option compadd -S = -a opts && ret=0
      ;;
      esac
    else
      _wanted mechanisms expl mechanism compadd -S '' avahi probe= && ret=0
    fi
  ;;
  pmiostat_extopts)
    _values -s , 'extended option' dm t h noidle && ret=0
  ;;
  scales_count)
    _values count-scale \
      "count x 10^-8" "count x 10^-7" "count x 10^-6" "count x 10^-5" \
      "count x 10^-4" "count x 10^-3" "count x 10^-2" "count x 10^-2" \
      "count x 10^-1" "count" "count x 10" "count x 10^2" "count x 10^3" \
      "count x 10^4" "count x 10^5" "count x 10^6" "count x 10^7" && ret=0
  ;;
  scales_space)
    _wanted space-scales expl 'space scale' compadd \
      -M 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \
      byte Kbyte KB Mbyte MB Gbyte GB Tbyte TB Pbyte PB Ebyte EB Zbyte ZB Ybyte YB && ret=0
  ;;
  scales_time)
    _values time-scale \
      nanosec ns microsec us millisec ms sec s minute min hour hr && ret=0
  ;;
  esac

  return ret
}

_pcp "$@"