summary refs log tree commit diff
path: root/Completion/Unix/Command/_tla
blob: 82af25899f454f7c5995fda5f809bcebcb0a902b (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
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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
#compdef tla

local arg_call opts_std opt_archive \
  opt_silent opt_quiet opt_report opt_verbose opt_debug opts_verbosity \
  opt_cache opt_dir opt_delete opt_errname opts_tag_method opt_readme \
  opt_reverse opt_summary opt_creator opt_date opt_full opt_dest opt_forward \
  opt_sparse opt_non_sparse opt_link opt_library
opts_std=(
  '--version[print version info]'
  '--help[display help]'
)
opt_archive=(
  '--archive[specify the default archive name]:archive:_tla_archives'
)
opt_library_archive=(
  '--archive[specify the default archive name]:archive:_tla_archives --library'
)
opt_silent=('(--quiet --report --verbose --debug)--silent[suppress messages]')
opt_quiet=('(--silent --report --verbose --debug)--quiet[brief output]')
opt_report=('(--silent --quiet --verbose --debug)--report[default output]')
opt_verbose=('(--silent --quiet --report --debug)--verbose[maximal output]')
opt_debug=('(--silent --quiet --report --verbose)--debug[debugging output]')
opts_verbosity=($opt_silent $opt_quiet $opt_report $opt_verbose $opt_debug)
opt_cache=(
  '--cache[specify directory for locally cached revisions]:directory: _files -/'
)
opt_dir=('--dir[operate on project tree in DIR]:DIR:_files -/')
opt_delete=('--delete[unspecify]')
opt_errname=('--errname[specify program name for errors]:program:_files')
opts_tag_method=(
  '--explicit[use explicit file tags]'
  '--implicit[use implicit file tags]'
  '--tagline[use tagline file tags]'
  '--names[use name-based file tags]'
)
opt_readme=('--readme[save FILE as the README for this archive]:file:_files')
opt_reverse=('--reverse[print in reverse order]')
opt_summary=('--summary[print a summary of each patch]')
opt_creator=('--creator[print the creator id of each patch]')
opt_date=('--date[print the date of each patch]')
opt_full=('--full[print full names of patch levels]')
opt_dest=(
  '--dest[create/modify DEST instead of the project tree]:DEST:_files -/'
)
opt_forward=('--forward[pass the --forward option to `patch'\'']')
opt_sparse=('(--non-sparse)--sparse[don'\''t fill in gaps in the library]')
opt_non_sparse=('(--sparse)--non-sparse[fill in gaps in the library]')
opt_link=('--link[hardlink files to revision library instead of copying]')
opt_library=('--library[ensure the revision is in a revision library]')

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

(( $+functions[_tla_categories] )) ||
_tla_categories () { _tla_namespace 1 "$argv[@]" }

(( $+functions[_tla_branches] )) ||
_tla_branches () {_tla_namespace 2 "$argv[@]" }

(( $+functions[_tla_versions] )) ||
_tla_versions () { _tla_namespace 3 "$argv[@]" }

(( $+functions[_tla_revisions] )) ||
_tla_revisions () { _tla_namespace 4 "$argv[@]" }

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

(( $+functions[_tla_namespace] )) ||
_tla_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=`tla my-default-archive`
  local trailing_dashes=0
  [[ -n $argv[(k)--trailing-dashes] ]] && trailing_dashes=1
  local library
  [[ -n $argv[(k)--library] ]] && library='library-';
  local exclude_library_revisions=0
  [[ -n $argv[(k)--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[@]" `tla ${library:-}categories -A $archive`
  elif [ -z $IPREFIX ]; then
    for (( i = 2 ; i < CURRENT ; i++ )); do
      if [ $words[$i] = -A ] || [ $words[$i] = --archive ]; then
        archive=$words[(($i + 1))]
        break
      fi
    done

    _description -V categories expl "${library:-}categories in $archive"
    compadd "$expl[@]" $suffix `tla ${library:-}categories -A $archive`
    _tla_archives -S / ${library:+--library}
  fi
  if [ $1 -gt 1 ] && [[ $PREFIX != *@* ]] && [[ $PREFIX = *--* ]]; then
  #this match could be better
    _tla_namespace_branches $(($1 - 1))
  fi
}

(( $+functions[_tla_namespace_branches] )) ||
_tla_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[@]" \
      `tla ${library:-}branches -A $archive $category | sed 's/^.*--//'`
  fi
  if [ $1 -gt 1 ] && [[ $IPREFIX = *-- ]] && [[ $PREFIX = *--* ]]; then
    _tla_namespace_versions $(($1 - 1))
  fi
}

(( $+functions[_tla_namespace_versions] )) ||
_tla_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[@]" \
      `tla ${library:-}versions -A $archive $branch | sed 's/^.*--//'`
  fi
  if [ $1 -gt 1 ] && [[ $IPREFIX = *--*-- ]] && ([[ $IPREFIX = */*--*-- ]] \
    || [[ $PREFIX != */* ]]) && [[ $PREFIX = *--* ]]; then
    _tla_namespace_revisions
  fi
}

(( $+functions[_tla_namespace_revisions] )) ||
_tla_namespace_revisions () {
  local expl
  if [[ $IPREFIX != *--*--*-- ]] || [[ $IPREFIX != */*--*--*-- ]]; then
    compset -P 1 '*--'
    local version=${IPREFIX%--}
    _description -V revisions expl "${library:-}revisions"
    local completions c
    completions=(`tla ${library:-}revisions -A $archive $version | sed 's/^.*--//'`)
    (( exclude_library_revisions )) && \
        foreach c ($(tla library-revisions -A $archive $version)); do completions[(k)$c]=(); done
    compadd "$expl[@]" -a completions
  fi
}

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

  # zsh 4.1.1+ is recommended; 4.0.6 gives the error below when doing
  # tla 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 tla tla 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[_tla_limit] )) ||
_tla_limit () { #presently only does push-mirror style limits
  [[ $words[$CURRENT] = *@* ]] && return 1

  local expl archive=`tla my-default-archive`

  for (( i = 2 ; i < CURRENT ; i++ )); do
    if [[ $words[$i] = *@* ]]; then
      archive=$words[$i]
      if tla archives -n | grep "$archive-SOURCE" > /dev/null; then
        archive=$archive-SOURCE
      fi
      break
    fi
  done

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

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

local _arg_call
_arg_call=(_arguments -S -A "-*" $opts_std)

(( $+functions[_tla_cmd_help] )) ||
_tla_cmd_help () { $_arg_call }

(( $+functions[_tla_cmd_my-id] )) ||
_tla_cmd_my-id () {
  $_arg_call $opt_errname \
    '--uid[print only the UID portion of the id]' \
    '::id-string:'
}

(( $+functions[_tla_cmd_my-default-archive] )) ||
_tla_cmd_my-default-archive () {
  $_arg_call $opt_archive $opt_errname $opt_silent $opt_delete \
    '::archive:_tla_archives'
}

(( $+functions[_tla_cmd_register-archive] )) ||
_tla_cmd_register-archive () {
  $_arg_call $opt_delete '--force[overwrite existing location]' \
    '::archive:_tla_archives' ':location:_files -/'
}

(( $+functions[_tla_cmd_whereis-archive] )) ||
_tla_cmd_whereis-archive () {
  $_arg_call ':archive:_tla_archives'
}

(( $+functions[_tla_cmd_archives] )) ||
_tla_cmd_archives () {
  $_arg_call '--names[print archive names only]' \
    '--exclude-remote[exclude MIRROR and SOURCE archives]' \
    '::regex:'
}

(( $+functions[_tla_cmd_init-tree] )) ||
_tla_cmd_init-tree () {
  $_arg_call $opt_archive $opt_dir \
    '--nested[init a nested project tree]' \
    '::version:_tla_versions'
}

(( $+functions[_tla_cmd_tree-root] )) ||
_tla_cmd_tree-root () {
  $_arg_call $opt_silent '--accurate[error for mid-txn trees]' \
    '::directory:_files -/'
}

(( $+functions[_tla_cmd_tree-version] )) ||
_tla_cmd_tree-version () { $_arg_call '::directory:_files -/' }

(( $+functions[_tla_cmd_set-tree-version] )) ||
_tla_cmd_set-tree-version () {
  $_arg_call $opt_archive $opt_dir ':version:_tla_versions'
}

(( $+functions[_tla_cmd_build-config] )) ||
_tla_cmd_build-config () {
  $_arg_call $opt_dir $opt_sparse $opt_link $opt_library \
    '--no-pristines[don'\''t create pristine copies]' \
    '--release-id[overwrite ./=RELEASE-ID for this config]' \
    ':config:_tla_config'
}

(( $+functions[_tla_cmd_cat-config] )) ||
_tla_cmd_cat-config () {
  $_arg_call $opt_dir \
    '--output[write the output as config CFG]:CFG:_tla_config' \
    '--force[overwrite an exiting config (with --output)]' \
    '--snap[show current patch levels of subtree packages]' \
    ':config:_tla_config'
}

(( $+functions[_tla_cmd_undo] )) ||
_tla_cmd_undo () {
  $_arg_call $opt_archive $opt_quiet $opt_dir $opt_forward \
    '(--no-output)--output[save changeset in DIR]:DIR:_files -/' \
    '(--output)--no-output[do not save the changeset]' \
    '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_redo] )) ||
_tla_cmd_redo() {
  $_arg_call $opt_quiet $opt_dir $opt_forward \
    '--keep[do not delete the patch]' \
    '::changeset:_files -/'
}

(( $+functions[_tla_cmd_changes] )) ||
_tla_cmd_changes () {
  $_arg_call $opt_archive $opt_verbose $opt_quiet $opt_dir \
    '--output[save changeset in DIR]:DIR:_files -/' \
    '--diffs[include diffs in the output]' \
    '(--output)--keep[don'\''t remove the output directory]' \
    '::revision:_tla_revisions'
  #  ':separator:(--)' '*::limit:_files'
  #don't understand the limit usage
}

(( $+functions[_tla_cmd_file-diffs] )) ||
_tla_cmd_file-diffs () {
  $_arg_call $opt_archive '--new-file[treat missing file as empty]' \
    ':file:_files' '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_file-find] )) ||
_tla_cmd_file-find () {
  $_arg_call $opt_archive \
    '--new-file[print missing file as `/dev/null'\'']' \
    ':file:_files' '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_inventory] )) ||
_tla_cmd_inventory () {
  $_arg_call $opts_tag_method '--source[list source files]' \
    '--precious[list precious files]' \
    '--backups[list backup files]' \
    '--junk[list junk files]' \
    '--unrecognized[list unrecognized files]' \
    '--trees[list roots of nested trees]' \
    '(--files --both)--directories[list only directories]' \
    '(--directories --both)--files[list only non-directories]' \
    '(--directories --files)--both[list both dirs and files]' \
    '--kind[indicate file kinds]' \
    '--all[show arch control files]' \
    '--nested[include nested trees]' \
    '--ids[list with ids (source files only)]' \
    '--untagged[include untagged files]' \
    '::separator:(--)' '*::directory:_files -/'
}

(( $+functions[_tla_cmd_tree-lint] )) ||
_tla_cmd_tree-lint () {
  $_arg_call '--broken-symlinks[just list broken symlinks]' \
    '--unrecognized-files[just list files violating naming conventions]' \
    '--untagged-files[just list files lacking inventory tags]' \
    '--missing-files[just list inventory tags lacking corresponding files]' \
    '--duplicate-tags[just list duplicated tags]' \
    '--strict[exit with non-0 status on _any_ oddity]' \
    '::directory:_files -/'
}

(( $+functions[_tla_cmd_id] )) ||
_tla_cmd_id () { $_arg_call $opts_tag_method $opt_silent '*:file:_files' }

(( $+functions[_tla_cmd_id-tagging-method] )) ||
_tla_cmd_id-tagging-method () {
  local 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'
  )
  $_arg_call $opt_dir '--strict[exit with error if method not set]' \
    '::tagging method:(($methods))'
}

(( $+functions[_tla_cmd_add-id] )) ||
_tla_cmd_add-id () {
  $_arg_call '--tag[specify TAG instead of auto-generating]:TAG:' \
    '*:files to add:_files'
}

(( $+functions[_tla_cmd_add] )) ||
_tla_cmd_add () { _tla_cmd_add-id "$@" }

(( $+functions[_tla_cmd_delete-id] )) ||
_tla_cmd_delete-id () {
  $_arg_call '*:files to delete:_files'
  #may want to check validity when expanding
}

(( $+functions[_tla_cmd_delete] )) ||
_tla_cmd_delete () { _tla_cmd_delete-id "$@" }

(( $+functions[_tla_cmd_move-id] )) ||
_tla_cmd_move-id () {
  $_arg_call ':old name:_files' ':new name:_files'
  #would be nice not to offer dirs for newname if oldname is a file, and
  #vice versa
}

(( $+functions[_tla_cmd_move] )) ||
_tla_cmd_move () { _tla_cmd_move-id "$@" }

(( $+functions[_tla_cmd_mv] )) ||
_tla_cmd_mv () {
  $_arg_call '*:file:_files'
  # this isn't quite right, but I can't get zsh to dtrt
}

(( $+functions[_tla_cmd_default-id] )) ||
_tla_cmd_default-id () {
  $_arg_call $opt_dir '--delete[remove the default]' \
    '--strong[use the strong default]' \
    '--weak[set a weak default]' \
    '--dont-care[use the dont-care default]' \
    '::TAG-PREFIX:'
}

(( $+functions[_tla_cmd_explicit-default] )) ||
_tla_cmd_explicit-default () { _tla_cmd_default-id "$@" }

(( $+functions[_tla_cmd_id-tagging-defaults] )) ||
_tla_cmd_id-tagging-defaults () { $_arg_call }

(( $+functions[_tla_cmd_changeset] )) ||
_tla_cmd_changeset () {
  $_arg_call \
    '--file-list[record only diffs of files listed in FILE]:file:_files' \
    ':ORIG:_files -/' ':MOD:_files -/' ':DEST:_files -/' '*::files:_files'
  #should command-line file list be allowed if --file-list is given?
}

(( $+functions[_tla_cmd_mkpatch] )) ||
_tla_cmd_mkpatch () { _tla_cmd_changeset "$@" }

(( $+functions[_tla_cmd_apply-changeset] )) ||
_tla_cmd_apply-changeset () {
  $_arg_call $opt_forward '--reverse[apply the changeset in reverse]' \
    ':changeset:_files -/' \
    ':target:_files -/'
}

(( $+functions[_tla_cmd_dopatch] )) ||
_tla_cmd_dopatch () { _tla_cmd_apply-changeset "$@" }

(( $+functions[_tla_cmd_show-changeset] )) ||
_tla_cmd_show-changeset () {
  $_arg_call '--diffs[include diff output]' '::changeset:_files -/'
}

(( $+functions[_tla_cmd_make-archive] )) ||
_tla_cmd_make-archive () {
  $_arg_call '--listing[keep .listing files up-to-date]' \
    '(--mirror-from)--mirror[create mirror of MASTER]:MASTER:_tla_archives' \
    '(--mirror)--mirror-from[create pull-based mirror of MASTER]:MASTER:_tla_archives' \
    '::name:' ':location:_files -/'
}

(( $+functions[_tla_cmd_archive-setup] )) ||
_tla_cmd_archive-setup () {
  $_arg_call $opt_archive \
    '--file[read the list of desired versions from FILE]:FILE:_files' \
    '--branches[make base-0 tags]' \
    '--cache[archive cache when creating base-0 tags]' \
    '*::versions:_tla_branches --trailing-dashes'
  #This doesn't take care of the subtleties at all
}

(( $+functions[_tla_cmd_make-category] )) ||
_tla_cmd_make-category () {
  $_arg_call $opt_archive ':category:_tla_archives -S /'
}

(( $+functions[_tla_cmd_make-branch] )) ||
_tla_cmd_make-branch () {
  $_arg_call $opt_archive ':branch:_tla_categories --trailing-dashes'
}

(( $+functions[_tla_cmd_make-version] )) ||
_tla_cmd_make-version () {
  $_arg_call $opt_archive ':version:_tla_branches --trailing-dashes'
}

(( $+functions[_tla_cmd_import] )) ||
_tla_cmd_import () {
  $_arg_call $opt_archive $opt_dir \
    '--log[commit with log file FILE]:FILE:_files' \
    '--summary[log with summary TEXT plus log-for-merge output]:TEXT:' \
    '--log-message[log with TEXT]:TEXT:' \
    '--setup[use `make-archive'\'' if necessary]' \
    '::version:_tla_versions'
}

(( $+functions[_tla_cmd_commit] )) ||
_tla_cmd_commit () {
  $_arg_call $opt_archive $opt_dir \
    '--log[commit with log file FILE]:FILE:_files' \
    '--summary[log with summary TEXT plus log-for-merge output]:TEXT:' \
    '--log-message[log with TEXT plus log-for-merge output]:TEXT:' \
    '--strict[strict tree-lint]' \
    '--seal[create a version-0 revision]' \
    '--fix[create a versionfix revision]' \
    '--out-of-date-ok[commit even if out of date]' \
    '--file-list[commit only mods to files listed in FILE]:FILE:_files' \
    '::version:_tla_versions' ':separator:(--)' '*:files:_files'
}

(( $+functions[_tla_cmd_get] )) ||
_tla_cmd_get () {
  $_arg_call $opt_archive $opt_silent $opt_sparse $opt_non_sparse $opt_link \
    $opt_library \
    '--cache[specify cache root for trees with pristines]:DIR:_files -/' \
    '--no-pristine[don'\''t save a pristine copy]' \
    ':revision:_tla_revisions' \
    '::directory:_files -/'
}

(( $+functions[_tla_cmd_get-changeset] )) ||
_tla_cmd_get-changeset () {
  $_arg_call $opt_archive ':revision:_tla_revisions' '::dir:_files -/'
}

(( $+functions[_tla_cmd_lock-revision] )) ||
_tla_cmd_lock-revision () {
  $_arg_call $opt_archive '--unlock[release a lock owned by you]' \
    '--break[break any existing lock]' \
    ':revision:_tla_revisions'
}

(( $+functions[_tla_cmd_archive-mirror] )) ||
_tla_cmd_archive-mirror () {
  $_arg_call \
    '(--cached-tags)--no-cached[don'\''t copy cached revisions]' \
    '(--no-cached)--cached-tags[copy only cachedrevs for tags to other archives]' \
    '::FROM or MINE:_tla_archives' '::TO:_tla_archives' '::LIMIT:_tla_limit'
  #TO should only be offered if FROM is given.
  #tla currently fails if limit is given without also passing an archive.
  #That should be fixed soon.
}

(( $+functions[_tla_cmd_categories] )) ||
_tla_cmd_categories () {
  $_arg_call $opt_archive '::archive:_tla_archives'
}

(( $+functions[_tla_cmd_branches] )) ||
_tla_cmd_branches () {
  $_arg_call $opt_archive '::category:_tla_categories'
}

(( $+functions[_tla_cmd_versions] )) ||
_tla_cmd_versions () {
  $_arg_call $opt_archive $opt_reverse \
    '::branch:_tla_branches'
}

(( $+functions[_tla_cmd_revisions] )) ||
_tla_cmd_revisions () {
  $_arg_call $opt_archive $opt_reverse $opt_summary $opt_creator \
    $opt_date $opt_full \
    '::version:_tla_versions'
    # Should complete revisions associated with the current tree too
}

(( $+functions[_tla_cmd_ancestry] )) ||
_tla_cmd_ancestry () {
  $_arg_call $opt_archive $opt_dir $opt_reverse $opt_summary $opt_creator \
    $opt_date \
    '--merges[show merges into this development line]' \
    '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_ancestry-graph] )) ||
_tla_cmd_ancestry-graph () {
  $_arg_call $opt_archive $opt_dir $opt_reverse \
    '--merges[show merges into this development line]' \
    '--immediate[show only the immediate ancestor]' \
    '--previous[show the (namespace) previous revision]' \
    '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_cat-archive-log] )) ||
_tla_cmd_cat-archive-log () {
  $_arg_call $opt_archive '--headers[show only log headers]' \
    ':revision:_tla_revisions'
}

(( $+functions[_tla_cmd_cacherev] )) ||
_tla_cmd_cacherev () {
  $_arg_call $opt_archive $opt_cache ':revision:_tla_revisions'
  #should only complete non-cached revisions
}

(( $+functions[_tla_cmd_cachedrevs] )) ||
_tla_cmd_cachedrevs () {
  $_arg_call $opt_archive ':version:_tla_versions'
}

(( $+functions[_tla_cmd_uncacherev] )) ||
_tla_cmd_uncacherev () {
  $_arg_call $opt_archive ':revision:_tla_revisions' '::dir:_files -/'
  #should only complete cached revisions
}

(( $+functions[_tla_cmd_archive-meta-info] )) ||
_tla_cmd_archive-meta-info () {
  $_arg_call $opt_archive ':item-name:(name mirror)'
  #What else is there to complete?
}

(( $+functions[_tla_cmd_archive-snapshot] )) ||
_tla_cmd_archive-snapshot () {
  $_arg_call $opt_archive ':dir:_files -/' '::limit:_tla_revisions'
}

(( $+functions[_tla_cmd_archive-version] )) ||
_tla_cmd_archive-version () { $_arg_call $opt_archive }

(( $+functions[_tla_cmd_archive-fixup] )) ||
_tla_cmd_archive-fixup () { $_arg_call $opt_archive }

(( $+functions[_tla_cmd_make-log] )) ||
_tla_cmd_make-log () {
  $_arg_call $opt_archive $opt_dir '::version:_tla_versions'
}

(( $+functions[_tla_cmd_log-versions] )) ||
_tla_cmd_log-versions () {
  $_arg_call $opt_reverse $opt_dir \
    '--archive[list only logs for ARCHIVE]:_tla_archives' \
    '--category[list only logs for CATEGORY:_tla_categories' \
    '--branch[list only logs for BRANCH]:_tla_branches' \
    '--vsn[list only logs for VERSION-NUMBER]:_tla_versions'
  # This should only complete items that are in the tree
}

(( $+functions[_tla_cmd_add-log-version] )) ||
_tla_cmd_add-log-version () {
  $_arg_call $opt_archive $opt_dir ':version:_tla_versions'
}

(( $+functions[_tla_cmd_remove-log-version] )) ||
_tla_cmd_remove-log-version () {
  $_arg_call $opt_archive $opt_dir \
    ':version:('"$(tla log-versions)"')'
}

(( $+functions[_tla_cmd_logs] )) ||
_tla_cmd_logs () {
  $_arg_call $opt_archive $opt_dir $opt_reverse $opt_summary \
    $opt_creator $opt_date $opt_full \
    '--local-merges[list merges from the same archive]' \
    '--foreign-merges[list merges from other archives]' \
    '--merges[list all merges]' \
    '*::version:('"$(tla log-versions)"')'
}

(( $+functions[_tla_cmd_abrowse] )) ||
_tla_cmd_abrowse () {
  $_arg_call $opt_archive $opt_reverse $opt_summary $opt_creator $opt_date \
    '--kind[show each revision kind (import, changeset or tag)]' \
    '--desc[implies -s -c -D -k]' \
    '--local-merges[list merges from the same archive]' \
    '--foreign-merges[list merges from other archives]' \
    '--merges[list all merges]' \
    '--categories[show category names only]' \
    '--branches[show branch names only]' \
    '--versions[show version names only]' \
    '--omit-empty[omit empty or unchanged-since items]' \
    '--since[show revisions after those listed in SNAP-FILE]:SNAP-FILE:_files' \
    '--since-limits[limit output to items in the since file]' \
    '--snap[record the highest revisions shown in SNAP-FILE]:SNAP-FILE:_files' \
    '--force[overwrite an existing snap-file]' \
    '::LIMIT:_tla_revisions'
}

(( $+functions[_tla_cmd_cat-log] )) ||
_tla_cmd_cat-log () {
  $_arg_call $opt_archive $opt_dir ':revision-spec:_tla_local_revisions'
}

(( $+functions[_tla_cmd_changelog] )) ||
_tla_cmd_changelog () {
  $_arg_call $opt_archive $opt_dir \
    '--no-files[exclude file lists from ChangeLog]' \
    '--untagged[don'\''t implicitly tag the output file]' \
    '--new-entry[make FILE the first (top) entry for patch level PATCH]:' \
    '::version:_tla_versions'
  #--new-entry could use a completion
}

(( $+functions[_tla_cmd_log-for-merge] )) ||
_tla_cmd_log-for-merge () {
  $_arg_call $opt_archive $opt_dir $opt_reverse \
    '::version:_tla_versions'
}

(( $+functions[_tla_cmd_merges] )) ||
_tla_cmd_merges () {
  $_arg_call $opt_archive $opt_dir $opt_reverse $opt_full \
    ':INTO:_tla_revisions' '::FROM:_tla_revisions'
}

(( $+functions[_tla_cmd_new-merges] )) ||
_tla_cmd_new-merges () {
  $_arg_call $opt_archive $opt_dir $opt_reverse '::version:_tla_versions'
}

(( $+functions[_tla_cmd_tag] )) ||
_tla_cmd_tag () {
  $_arg_call $opt_archive '--log[commit with log file FILE]:FILE:_files' \
    '--seal[create a version-0 revision]' \
    '--fix[create a versionfix revision]' \
    ':SOURCE-REVISION:_tla_revisions' ':TAG_VERSION:_tla_versions'
}

(( $+functions[_tla_cmd_update] )) ||
_tla_cmd_update () {
  $_arg_call $opt_archive $opt_dir $opt_dest $opt_forward \
    '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_join-branch] )) ||
_tla_cmd_join-branch () {
  $_arg_call $opt_archive $opt_dir $opt_dest ':revision:_tla_revisions'
  #should only complete continuation revisions
}

(( $+functions[_tla_cmd_replay] )) ||
_tla_cmd_replay () {
  $_arg_call $opt_archive $opt_dir $opt_dest $opt_forward \
    '--list[read a list of patches to apply from FILE]:FILE:_files' \
    '--new[replay only new patches]' \
    '--reverse[reverse the named patch]' \
    '--skip-present[skip patches that contain 1 or more patch logs already in this tree]' \
    '*::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_star-merge] )) ||
_tla_cmd_star-merge () {
  $_arg_call $opt_archive $opt_dir $opt_forward \
    '--changes[save changeset in OUTPUT, but don'\''t apply]:OUTPUT:_files -/' \
    '--reference[set reference version]:VERSION:_tla_versions' \
    '--three-way[Perform a 3-way (diff3-style) merge]' \
    ':FROM:_tla_revisions'
}

(( $+functions[_tla_cmd_apply-delta] )) ||
_tla_cmd_apply-delta () {
  $_arg_call $opt_archive $opt_cache $opt_dir $opt_dest $opt_forward \
    ':FROM:_tla_tree_or_rev' \
    ':TO:_tla_tree_or_rev'
}

(( $+functions[_tla_cmd_missing] )) ||
_tla_cmd_missing () {
  $_arg_call $opt_archive $opt_dir $opt_reverse $opt_summary $opt_creator \
    $opt_date $opt_full '--merges[print a merge list for each missing patch]' \
    '--skip-present[skip patches that contain 1 or more patch logs already in this tree]' \
    '::revision:_tla_revisions'
}

(( $+functions[_tla_cmd_sync-tree] )) ||
_tla_cmd_sync-tree () {
  $_arg_call $opt_archive $opt_dir $opt_dest ':revision:_tla_revisions'
}

(( $+functions[_tla_cmd_delta] )) ||
_tla_cmd_delta () {
  $_arg_call $opt_archive $opt_cache \
    '--report[output a changeset report]' \
    '--no-changeset[don'\''t save the delta]' \
    ':FROM:_tla_tree_or_rev' \
    ':TO:_tla_tree_or_rev' \
    '::DEST:_files -/'
}

(( $+functions[_tla_cmd_pristines] )) ||
_tla_cmd_pristines () {
  $_arg_call $opt_dir $opt_reverse \
    '--unlocked[return only unlocked pristines]' \
    '--locked[return only locked pristines]' \
    '::limit:_tla_revisions'
  #limit apparently needs at least a branch?
}

(( $+functions[_tla_cmd_lock-pristine] )) ||
_tla_cmd_lock-pristine () {
  $_arg_call $opt_archive $opt_dir \
    '--unlock[unlock, rather than lock]' \
    ':revision:_tla_revisions'
}

(( $+functions[_tla_cmd_add-pristine] )) ||
_tla_cmd_add-pristine () {
  $_arg_call $opt_archive $opt_dir ':revision:_tla_revisions'
  #should it only complete revisions that match the project tree?
}

(( $+functions[_tla_cmd_find-pristine] )) ||
_tla_cmd_find-pristine () {
  $_arg_call $opt_archive $opt_dir $opt_silent \
    '--unlocked[return only an unlocked pristine]' \
    '--locked[return only a locked pristine]' \
    '--tree-only[search this tree only, not siblings]' \
    ':revision:_tla_revisions'
}

(( $+functions[_tla_cmd_my-revision-library] )) ||
_tla_cmd_my-revision-library () {
  $_arg_call $opt_errname $opt_delete $opt_silent \
    '--search[use the full search path]' \
    '--add[use the full add path]' \
    '--search-only[use the search-only path]' \
    '--add-only[use the add-only path]' \
    '--first[prepend to the path if setting (default appends)]' \
    '::dir:_files -/'
}

(( $+functions[_tla_cmd_library-find] )) ||
_tla_cmd_library-find () {
  $_arg_call $opt_library_archive $opt_errname $opt_silent \
  ':revision:_tla_revisions --library'
}

(( $+functions[_tla_cmd_library-add] )) ||
_tla_cmd_library-add () {
  $_arg_call $opt_archive $opt_sparse $opt_non_sparse \
    '--library[specify which library to add to]:LIB:_files -/' \
    '--for-links[require a lib on the same device as PATH]:PATH:_files -/' \
    ':revision:_tla_revisions --exclude-library-revisions'
  #ought to have a _tla_libraries function to comlete libraries
}

(( $+functions[_tla_cmd_library-remove] )) ||
_tla_cmd_library-remove () {
  $_arg_call $opt_library_archive ':revision:_tla_revisions --library'
}

(( $+functions[_tla_cmd_library-archives] )) ||
_tla_cmd_library-archives () {
  $_arg_call
}

(( $+functions[_tla_cmd_library-categories] )) ||
_tla_cmd_library-categories () {
  $_arg_call $opt_library_archive '::archive:_tla_archives --library'
}

(( $+functions[_tla_cmd_library-branches] )) ||
_tla_cmd_library-branches () {
  $_arg_call $opt_library_archive '::category:_tla_categories --library'
}

(( $+functions[_tla_cmd_library-versions] )) ||
_tla_cmd_library-versions () {
  $_arg_call $opt_library_archive $opt_reverse \
    '::branch:_tla_branches --library'
}

(( $+functions[_tla_cmd_library-revisions] )) ||
_tla_cmd_library-revisions () {
  $_arg_call $opt_library_archive $opt_reverse $opt_full $opt_summary \
    $opt_creator $opt_date '::version:_tla_versions --library'
}

(( $+functions[_tla_cmd_library-log] )) ||
_tla_cmd_library-log () {
  $_arg_call $opt_silent $opt_library_archive ':revision:_tla_revisions --library'
}

(( $+functions[_tla_cmd_library-file] )) ||
_tla_cmd_library-file () {
  $_arg_call $opt_library_archive '--tag[interpret file as an inventory tag]' \
           '--this[interpret file as a file within a project tree]' \
           ':file:_files' ':revision:_tla_revisions --library'
}

(( $+functions[_tla_cmd_grab] )) ||
_tla_cmd_grab () {
  $_arg_call ':location:_files'
}

(( $+functions[_tla_cmd_parse-package-name] )) ||
_tla_cmd_parse-package-name () {
  $_arg_call $opt_archive \
    '--arch[print the archive name]' \
    '--non-arch[print the non-archive part of the name]' \
    '--category[print the category name]' \
    '--branch[print the branch name]' \
    '--package[print the package name]' \
    '--vsn[print the version id]' \
    '--package-version[print the category--branch--version]' \
    '--lvl[print the patch level]' \
    ':name:'
}

(( $+functions[_tla_cmd_valid-package-name] )) ||
_tla_cmd_valid-package-name () {
  $_arg_call $opt_errname \
    '--archive[require an explicit archive]' \
    '--no-archive[prohibit an explicit archive]' \
    '--category[require a category]' \
    '--package[require category, permit branch]' \
    '--vsn[require a version number]' \
    '--lvl[require a patch level]' \
    '--tolerant[tolerate more specific names]' \
    ':name:'
}

(( $+functions[_tla_cmd_library-config] )) ||
_tla_cmd_library-config () {
  $_arg_call $opt_sparse $opt_non_sparse \
  '(--non-greedy)--greedy[make the library greedy]' \
    '(--greedy)--non-greedy[make the library non-greedy]' \
    ':library-dir:_files -/'
}

(( $+functions[_tla_cmd_rbrowse] )) ||
_tla_cmd_rbrowse () {
  $_arg_call '(--archive)--search-all[search all archives]' \
    '(--search-all)--archive[use ARCHIVE instead of default]:ARCHIVE:_tla_archives' \
    '::regular expression:'
}

_tla_main () {
  typeset -A opt_args
  if (( CURRENT > 2 )); then
    local cmd=${words[2]}
    curcontext="${curcontext%:*:*}:tla-$cmd:"
    (( CURRENT-- ))
    shift words
    if typeset -f _tla_cmd_$cmd &>/dev/null; then
      _tla_cmd_$cmd
    else
      _arguments '*:: :_files'
    fi
  else
    _arguments $opts_std ':commands:(($cmds))'
  fi
}

local -U cmds
local help
help=(${(f)"$(tla help)"})
cmds=(${${${${(M)help:#* :*}/ #: #/:}%% ##}## #})

_tla_main "$@"