about summary refs log tree commit diff
path: root/Completion/Unix/Command/_baz
blob: 9b172f851f7c2449935d477c41e1f9461b05a814 (plain) (blame)
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
#compdef baz

autoload is-at-least
local BAZ=$words[1]
local baz_version
local hide_short

# ask the user which version of baz this is
if ! zstyle -s ":completion:${curcontext}" baz-version baz_version; then
  # ask baz instead
  baz_version="${${$($BAZ --version)#baz baz-}%% from regexps.com*}"
fi

# test whether to hide short options from completion
if zstyle -s ":completion:${curcontext}" hide-shortopts hide_short; then
  case $hide_short in
    true|yes|on|1) hide_short='!' ;;
    *) hide_short='' ;;
  esac
fi

# completion functions

(( $+functions[_baz_archives] )) ||
_baz_archives () {
  local expl completions library name_arg='-n'
  if [[ -n $argv[(r)--library] ]]; then
    library='library-'
    # remove parameter from $@ before calling compadd
    argv[(r)--library]=()
    name_arg=
  fi
  completions=($(_call_program baz $BAZ ${library:-}archives $name_arg))
  _description -V archives expl "${library:-}archives"
  compadd "$@" "$expl[@]" -- "$completions[@]"
}

(( $+functions[_baz_categories] )) ||
_baz_categories () { _baz_namespace 1 "$argv[@]" }

(( $+functions[_baz_branches] )) ||
_baz_branches () {_baz_namespace 2 "$argv[@]" }

(( $+functions[_baz_versions] )) ||
_baz_versions () { _baz_namespace 3 "$argv[@]" }

(( $+functions[_baz_revisions] )) ||
_baz_revisions () { _baz_namespace 4 "$argv[@]" }

(( $+functions[_baz_local_revisions] )) ||
_baz_local_revisions () {
  local expl1 expl2 tree_version=`$BAZ tree-version`
  _description -V applied-patches expl1 "patches from this version"
  _description -V other-patches expl2 "patches from other versions"
  compadd "$expl1[@]" `$BAZ logs`
  compadd "$expl2[@]" `$BAZ logs --full $($BAZ log-versions | grep -v $tree_version)`
  # This is incredibly slow.
  # Should complete based on -A, -R, -d
}

(( $+functions[_baz_namespace] )) ||
_baz_namespace () { #double as arch_namespace_categories
# takes an integer argument specifying how many components:
# 1: category
# 2: branch
# 3: version
# 4: revision
  local suffix expl archive=`$BAZ my-default-archive 2> /dev/null`
  local trailing_dashes=0
  [[ -n $argv[(r)--trailing-dashes] ]] && trailing_dashes=1
  local library
  [[ -n $argv[(r)--library] ]] && library='library-';
  local exclude_library_revisions=0
  [[ -n $argv[(r)--exclude-library-revisions] ]] && exclude_library_revisions=1

  if [ $1 -gt 1 ] || (( trailing_dashes )); then
    suffix=(-q -S --)
  fi
  if [[ $PREFIX = */* ]]; then
    compset -P '*/'
    archive=${IPREFIX%/*}
    _description -V categories expl "${library:-}categories in $archive"
    compadd $suffix "$expl[@]" `$BAZ ${library:-}categories -A $archive`
  elif [ -z $IPREFIX ]; then
    local index=$(( words[(i)-A] + 1 ))
    (( index < CURRENT )) || index=$(( words[(i)--archive] + 1 ))
    (( index < CURRENT )) && archive=$words[$index]

    if [ $archive ]; then
      _description -V categories expl "${library:-}categories in $archive"
      compadd "$expl[@]" $suffix `$BAZ ${library:-}categories -A $archive`
    fi

    _baz_archives -S / ${library:+--library}
  fi
  if [ $archive ] && [ $1 -gt 1 ] && [[ $PREFIX != *@* ]] \
     && [[ $PREFIX = *--* ]]; then
  #this match could be better
    _baz_namespace_branches $(($1 - 1))
  fi
}

(( $+functions[_baz_namespace_branches] )) ||
_baz_namespace_branches () {
  local suffix expl
  if [ $1 -gt 1 ] || (( $trailing_dashes )); then
    suffix=(-q -S --)
  fi
  if [[ $IPREFIX != *-- ]]; then
    compset -P 1 '*--'
    local category=${IPREFIX%--}
    _description -V branches expl "${library:-}branches"
    compadd $suffix "$expl[@]" \
      ${${(@)$($BAZ ${library:-}branches -A $archive $category)}##*--}
  fi
  if [ $1 -gt 1 ] && [[ $IPREFIX = *-- ]] && [[ $PREFIX = *--* ]]; then
    _baz_namespace_versions $(($1 - 1))
  fi
}

(( $+functions[_baz_namespace_versions] )) ||
_baz_namespace_versions () {
  local suffix expl
  if [ $1 -gt 1 ]; then
    suffix=(-q -S --)
  fi
  if [[ $IPREFIX != *--*-- ]] || [[ $IPREFIX != */*--*-- ]]; then
    compset -P 1 '*--'
    local branch=${IPREFIX%--}
    _description -V versions expl "${library:-}versions"
    compadd $suffix "$expl[@]" \
      ${${(@)$($BAZ ${library:-}versions -A $archive $branch)}##*--}
  fi
  if [ $1 -gt 1 ] && [[ $IPREFIX = *--*-- ]] && ([[ $IPREFIX = */*--*-- ]] \
    || [[ $PREFIX != */* ]]) && [[ $PREFIX = *--* ]]; then
    _baz_namespace_revisions
  fi
}

(( $+functions[_baz_namespace_revisions] )) ||
_baz_namespace_revisions () {
  local expl
  if [[ $IPREFIX != *--*--*-- ]] || [[ $IPREFIX != */*--*--*-- ]]; then
    compset -P 1 '*--'
    local version=${IPREFIX%--}
    _description -V revisions expl "${library:-}revisions"
    local completions c
    completions=(
      ${${(@)$($BAZ ${library:-}revisions -A $archive $version)}##*--}
    )
    (( exclude_library_revisions )) && \
        foreach c ($($BAZ library-revisions -A $archive $version)); do completions[(r)$c]=(); done
    compadd "$expl[@]" -a completions
  fi
}

(( $+functions[_baz_config] )) ||
_baz_config () {

  # zsh 4.1.1+ is recommended; 4.0.6 gives the error below when doing
  # baz build-config e<TAB>
  # _path_files:322: no matches found: configs//e/.(/)
  # whereas 4.1.1 completes correctly

  local configdir root ret=1 n expl

  n=$opt_args[(i)(-d|--dir)]
  [[ -n "$n" ]] && configdir=$opt_args[$n]
  root="$(_call_program baz $BAZ tree-root ${configdir} 2>&1)"
  if (( $? )); then
    _message -e messages "Error: $root"
    return $ret
  fi

  if [[ -d "$root/configs" ]]; then
    configdir=("$root/configs")
    _description files expl '%Bconfig file%b'
    _files -W configdir "$expl[@]" && ret=0
  else
    _message -e messages "No configs/ directory in tree whose root is $root"
  fi
  return $ret
}

(( $+functions[_baz_limit] )) ||
_baz_limit () { #presently only does push-mirror style limits
  [[ $words[$CURRENT] == *@* ]] && return 1

  local expl archive
  archive=${words[(r)*@*]:-$($BAZ my-default-archive 2> /dev/null)}
  if [ $archive ]; then

    if [[ $PREFIX != *--* ]]; then
      _description -V categories expl "categories in $archive"
      compadd -q -S -- "$expl[@]" `$BAZ categories -A $archive`
    else
      _baz_namespace_branches 3
    fi
  fi
}

(( $+functions[_baz_tree_or_rev] )) ||
_baz_tree_or_rev () {
  _alternative 'trees:tree:_files -/' 'revisions:revision:_baz_revisions'
}

(( $+functions[_baz_libraries] )) ||
_baz_libraries () {
  local libraries expl
  libraries=($(_call_program baz $BAZ my-revision-library))
  _description -V libraries expl "revision libraries"
  compadd "$expl[@]" -a libraries
}

(( $+functions[_baz_my_revision_library] )) ||
_baz_my_revision_library () {
  if [[ -n $words[(r)-d] ]] || [[ -n $words[(r)--delete] ]]; then
    _baz_libraries
  else
    _files -/
  fi
}

(( $+functions[_baz_log_versions] )) ||
_baz_log_versions () {
  local logs expl
  logs=($(_call_program baz $BAZ log-versions))
  _description -V versions expl "log versions"
  compadd "$expl[@]" -a logs
}

# command argument definitions
# commands with different versions

local cmd_register_archive cmd_archives cmd_ls_archives cmd_redo
local cmd_redo_changes cmd_changes cmd_what_changed cmd_categories
local cmd_branches cmd_versions cmd_cacherev cmd_logs cmd_log_versions
local cmd_log_ls cmd_update cmd_join_branch cmd_replay cmd_deltapatch
local cmd_delta_patch cmd_apply_delta cmd_sync_tree cmd_make_sync_tree
local cmd_delta cmd_revdelta cmd_library_categories cmd_library_branches
local cmd_library_versions cmd_library_revisions

cmd_log_ls=('*:version:_baz_log_versions')
cmd_log_versions=()
# the options should only complete items that are in the tree

cmd_register_archive=('::archive:_baz_archives' ':location:_files -/')
cmd_archives=('::regex:')
cmd_redo=('::changeset:_files -/')
cmd_changes=('::revision:_baz_revisions'
  #  ':separator:(--)' '*::limit:_files'
  #don't understand the limit usage
)
cmd_categories=('::archive:_baz_archives')
cmd_branches=('::category:_baz_categories')
cmd_versions=('::branch:_baz_branches')
cmd_cacherev=('::revision:_baz_revisions')
#should only complete non-cached revisions

cmd_logs=($cmd_log_ls)
cmd_update=('::revision:_baz_revisions')
cmd_join_branch=(':revision:_baz_revisions')
#should only complete continuation revisions

cmd_replay=('*::revision:_baz_revisions')
cmd_deltapatch=(':FROM:_baz_tree_or_rev' ':TO:_baz_tree_or_rev')
cmd_sync_tree=(':revision:_baz_revisions')
cmd_delta=(':FROM:_baz_tree_or_rev' ':TO:_baz_tree_or_rev' '::DEST:_files -/')
cmd_library_categories=('::archive:_baz_archives --library')
cmd_library_branches=('::category:_baz_categories --library')
cmd_library_versions=('::branch:_baz_branches --library')
cmd_library_revisions=('::version:_baz_versions --library')

cmd_ls_archives=($cmd_archives)
cmd_redo_changes=($cmd_redo)
cmd_what_changed=($cmd_changes)
cmd_delta_patch=($cmd_deltapatch)
cmd_apply_delta=($cmd_deltapatch)
cmd_make_sync_tree=($cmd_sync_tree)
cmd_revdelta=($cmd_delta)

# commands the same in all versions

local cmd_help
cmd_help=()

local cmd_my_id
cmd_my_id=('::id-string:')

local cmd_my_default_archive
cmd_my_default_archive=('::archive:_baz_archives')

local cmd_whereis_archive
cmd_whereis_archive=(':archive:_baz_archives')

local cmd_init_tree
cmd_init_tree=('::version:_baz_versions')

local cmd_tree_root
cmd_tree_root=('::directory:_files -/')

local cmd_tree_version
cmd_tree_version=('::directory:_files -/')

local cmd_set_tree_version
cmd_set_tree_version=(':version:_baz_versions')

local cmd_build_config cmd_buildcfg
cmd_build_config=(':config:_baz_config')
cmd_buildcfg=($cmd_build_config)

local cmd_cat_config cmd_catcfg cmd_cfgcat
cmd_cat_config=(':config:_baz_config')
cmd_catcfg=($cmd_cat_config)
cmd_cfgcat=($cmd_cat_config)

local cmd_undo cmd_undo_changes
cmd_undo=('::revision:_baz_revisions')
cmd_undo_changes=($cmd_undo)

local cmd_file_diffs
cmd_file_diffs=(':file:_files' '::revision:_baz_revisions')

local cmd_file_find
cmd_file_find=(':file:_files' '::revision:_baz_revisions')

local cmd_inventory cmd_srcfind
cmd_inventory=('::separator:(--)' '*:directory:_files -/')
cmd_srcfind=($cmd_inventory)

local cmd_lint
cmd__lint=('::directory:_files -/')

local cmd_id cmd_invtag
cmd_id=('*:file:_files')
cmd_invtag=($cmd_id)

local cmd_id_tagging_method cmd_tagging_method methods
cmd_id_tagging_method=('::tagging method:(($methods))')
methods=(
  'names:use naming conventions only'
  'implicit:use naming conventions but permit for inventory tags'
  'tagline:use naming conventions but permit for inventory tags'
  'explicit:require explicit designation of source'
)
cmd_tagging_method=($cmd_id_tagging_method)

local cmd_add cmd_add_id cmd_add_tag
cmd_add=('*:files to add:_files')
cmd_add_id=($cmd_add)
cmd_add_tag=($cmd_add)

local cmd_delete cmd_delete_id cmd_delete_tag
cmd_delete=('*:files to delete:_files')
cmd_delete_id=($cmd_delete)
cmd_delete_tag=($cmd_delete)

local cmd_move cmd_move_id cmd_move_tag
cmd_move_id=(':old name:_files' ':new name:_files')
cmd_move_id=($cmd_move)
cmd_move_tag=($cmd_move)
#would be nice not to offer dirs for newname if oldname is a file, and
#vice versa

local cmd_mv
cmd_mv=('*:file:_files')
# not really right, but close enough

local cmd_default_id cmd_explicit_default cmd_default_tag
cmd_default_id=('::TAG-PREFIX:')
cmd_explicit_default=($cmd_default_id)
cmd_default_tag=($cmd_default_id)

local cmd_tagging_defaults cmd_id_tagging_defaults
cmd_tagging_defaults=()
cmd_id_tagging_defaults=($cmd_tagging_defaults)

local cmd_changeset cmd_mkpatch
cmd_changeset=(
  ':ORIG:_files -/'
  ':MOD:_files -/'
  ':DEST:_files -/'
  '*:files:_files'
)
cmd_mkpatch=("$cmd_changeset[@]")

local cmd_dopatch cmd_do_changeset cmd_apply_changeset
cmd_dopatch=(':changeset:_files -/' ':target:_files -/')
cmd_do_changeset=($cmd_dopatch)
cmd_apply_changeset=($cmd_dopatch)

local cmd_show_changeset
cmd_show_changeset=('::changeset:_files -/')

local cmd_make_archive
cmd_make_archive=('::name:' ':location:_files -/')

local cmd_archive_setup
cmd_archive_setup=('*:versions:_baz_branches --trailing-dashes')

local cmd_make_category
cmd_make_category=(':category:_baz_archives -S /')

local cmd_make_branch
cmd_make_branch=(':branch:_baz_categories --trailing-dashes')

local cmd_make_version
cmd_make_version=(':version:_baz_branches --trailing-dashes')

local cmd_import cmd_imprev
cmd_import=('::version:_baz_versions')
cmd_imprev=($cmd_import)

local cmd_commit cmd_cmtrev
cmd_commit=('::version:_baz_versions' ':separator:(--)' '*:files:_files')
cmd_cmtrev=($cmd_commit)

local cmd_get cmd_getrev
cmd_get=(':revision:_baz_revisions' '::directory:_files -/')
cmd_getrev=($cmd_get)

local cmd_get_patch cmd_get_changeset
cmd_get_patch=(':revision:_baz_revisions' '::dir:_files -/')
cmd_get_changeset=($cmd_get_patch)

local cmd_lock_revision
cmd_lock_revision=(':revision:_baz_revisions')

local cmd_push_mirror cmd_archive_mirror
cmd_push_mirror=(
  '::FROM or MINE:_baz_archives'
  '::TO:_baz_archives'
  '::LIMIT:_baz_limit'
)
cmd_archive_mirror=($cmd_push_mirror)

local cmd_revisions
cmd_revisions=('::version:_baz_versions')

local cmd_ancestry
cmd_ancestry=('::revision:_baz_revisions')

local cmd_ancestry_graph
cmd_ancestry_graph=('::revision:_baz_revisions')

local cmd_cat_archive_log
cmd_cat_archive_log=(':revision:_baz_revisions')

local cmd_cachedrevs
cmd_cachedrevs=(':version:_baz_versions')

local cmd_uncacherev
cmd_uncacherev=(':revision:_baz_revisions' '::dir:_files -/')

local cmd_archive_meta_info
cmd_archive_meta_info=(':item-name:((name\:foo mirror\:bar))')

local cmd_archive_snapshot
cmd_archive_snapshot=(':dir:_files -/' '::limit:_baz_revisions')

local cmd_archive_version
cmd_archive_version=()

local cmd_archive_fixup
cmd_archive_fixup=()

local cmd_make_log
cmd_make_log=('::version:_baz_versions')

local cmd_add_log cmd_add_log_version
cmd_add_log=(':version:_baz_versions')
cmd_add_log_version=($cmd_add_log)

local cmd_remove_log cmd_remove_log_version
cmd_remove_log=(':version:_baz_log_versions')
cmd_remove_log_version=($cmd_remove_log)

local cmd_abrowse
cmd_abrowse=('::LIMIT:_baz_revisions')

local cmd_cat_log
cmd_cat_log=(':revision-spec:_baz_local_revisions')

local cmd_changelog
cmd_changelog=('::version:_baz_versions')

local cmd_log_for_merge
cmd_log_for_merge=('::version:_baz_versions')

local cmd_merges
cmd_merges=(':INTO:_baz_revisions' '::FROM:_baz_revisions')

local cmd_new_merges
cmd_new_merges=('::version:_baz_versions')

local cmd_branch
cmd_branch=(':SOURCE-REVISION:_baz_revisions' ':TAG-VERSION:_baz_versions')

local cmd_star_merge
cmd_star_merge=(':FROM:_baz_revisions')

local cmd_missing cmd_whats_missing
cmd_missing=('::revision:_baz_revisions')
cmd_whats_missing=($cmd_missing)

local cmd_pristines cmd_ls_pristines
cmd_pristines=('::limit:_baz_revisions')
cmd_ls_pristines=($cmd_pristines)

local cmd_lock_pristine
cmd_lock_pristine=(':revision:_baz_revisions')

local cmd_add_pristine
cmd_add_pristine=(':revision:_baz_revisions')

local cmd_find_pristine
cmd_find_pristine=(':revision:_baz_revisions')

local cmd_my_revision_library
cmd_my_revision_library=(':library:_baz_my_revision_library')

local cmd_library_find
cmd_library_find=(':revision:_baz_revisions --library')

local cmd_library_add
cmd_library_add=(':revision:_baz_revisions --exclude-library-revisions')

local cmd_library_remove
cmd_library_remove=(':revision:_baz_revisions --library')

local cmd_library_archives
cmd_library_archives=()

local cmd_library_log
cmd_library_log=(':revision:_baz_revisions --library')

local cmd_library_file
cmd_library_file=(':file:_files' ':revision:_baz_revisions --library')

local cmd_grab
cmd_grab=(':location:_files')

local cmd_parse_package_name
cmd_parse_package_name=(':name:')

local cmd_valid_package_name
cmd_valid_package_name=(':name:')

local cmd_library_config
cmd_library_config=(':library:_baz_libraries')

local cmd_rbrowse
cmd_rbrowse=('::regular expression:')

local cmd_rm
cmd_rm=('*:file:_files')

local cmd_escape
cmd_escape=(':string:')

#mutually exclusive options

local -A excludes
excludes=(
# This first line means that if --output was given, don't complete
# --no-output or --keep. The converse is not true.
--output '--no-output --keep'
--no-output --output

--silent  '         --quiet --report --verbose --debug'
--quiet   '--silent         --report --verbose --debug'
--report  '--silent --quiet          --verbose --debug'
--verbose '--silent --quiet --report           --debug'
--debug   '--silent --quiet --report --verbose        '

--sparse --non-sparse
--non-sparse --sparse

--files       '        --directories --both'
--directories '--files               --both'
--both        '--files --directories       '

--mirror --mirror-from
--mirror-from --mirror

--no-cached --cached-tags
--cached-tags --no-cached

--non-greedy --greedy
--greedy --non-greedy
)

_baz_main () {
  typeset -A opt_args
  local arguments
  if (( CURRENT > 2 )); then
    local cmd=${words[2]}
    local var_cmd=cmd_${cmd//-/_}
    curcontext="${curcontext%:*:*}:baz-$cmd:"
    (( CURRENT-- ))
    shift words

    arguments=()
    local input
    input=(${${(f)"$($BAZ $cmd -h)"}#  })
    shift 6 input

    local i j=1
    local short long arg desc action
    short=()
    long=()
    arg=()
    desc=()
    action=()
    for (( i=1 ; i <= ${#input} ; i++ )); do
      [[ "$input[i]" != *[^\ ]* ]] && continue # stupid blank lines
      short[j]="${${${input[i]}[1,2]}#--}"
      long[j]="${${input[i]#-?, }%% *}"

      arg[j]="${${${input[i]%%  *}##* }##-*}"
      [[ $long[j] == --archive ]] && arg[j]=ARCHIVE # baz doesn't mention this

      desc[j]="${input[i]##*  }"
      if [[ "$input[i+1]" == \ *[^\ ]* ]]; then # description continues
        (( i++ ))
        desc[j]="$desc[j] ${input[i]##*  }"
      fi
      desc[j]="${${desc[j]//\[/\\[}//\]/\\]}" # escape brackets

      case $arg[j] in
      DIR|PATCH-DIR|DEST|OUTPUT|PATH)
        action[j]='_files -/' ;;
      FILES|FILE|SNAP-FILE)
        action[j]='_files' ;;
      MASTER|MASTER-SOURCE|ARCHIVE)
        action[j]='_baz_archives' ;;
      CATEGORY)
        action[j]='_baz_categories' ;;
      BRANCH)
        action[j]='_baz_branches' ;;
      VERSION)
        action[j]='_baz_versions' ;;
      CFG)
        action[j]='_baz_configs' ;;
      LIB)
        action[j]='_baz_libraries' ;;
#      PATCH,FILE) # not sure how to complete this
#        action[j]='_baz_patch_file' ;;
      *)
        action[j]='' ;;
      esac

      (( j++ ))

    done

    local excluded k
    for (( i = 1 ; i < j ; i++ )); do
      excluded=($short[i] $long[i])
      foreach opt (${=excludes[$long[i]]})
        k=$long[(i)$opt]
        excluded=($excluded $short[k] $long[k])
        #excludes matching short options too :-)
      end


      # generate arguments to _arguments ;-)
      # make long and short options mutually exclusive
      [ $short[i] ] && arguments=("$arguments[@]"
        "${hide_short}(${excluded})${short[i]}[${desc[i]}]${arg[i]:+:$arg[i]:$action[i]}")
      [ $long[i] ] && arguments=("$arguments[@]"
        "(${excluded})${long[i]}[${desc[i]}]${arg[i]:+:$arg[i]:$action[i]}")
    done

    arguments=("$arguments[@]" "${(@P)var_cmd-*:FILE:_files}")
  else
    local help
    local -U cmds
    help=(${(f)"$($BAZ help)"})
    cmds=(${${${${(M)help:#* :*}/ #: #/:}%% ##}## #})
    arguments=(':commands:(($cmds))')
  fi
  _arguments -S -A '-*' \
    {"${hide_short}(: -)-V",'(: -)--version'}'[display version]' \
    {"${hide_short}(: -)-h",'(: -)--help'}'[display help]' \
    '(: -)-H[display verbose help]' \
    "$arguments[@]"
}

_baz_main "$@"