gunk-dev/the-valley

_valley

source81eeeb107e7cmain's published tip history
3.9 KiB
1#compdef valley
2# zsh completion for valley. The verb list mirrors the case statement in
3# bin/valley — update both together.
4#
5# NEVER fetch from here: completion runs on every <TAB> and must be instant.
6# Candidates come from the remote-tracking refs of the last fetch; valley's
7# own verbs fetch before acting, so stale candidates cost nothing.
8
9_valley() {
10 if (( CURRENT == 2 )); then
11 local -a verbs=(
12 'pending:list the changes not yet landed, the unrecorded branches, and the drafts'
13 'changes:print every change, across the host, as valley-changes/v1 JSON'
14 'review:page through a branch, then approve, reject, or skip'
15 'approve:approve a change without paging it, filing its integration request'
16 'rebase:rebase a change onto origin/main and push it with a lease'
17 'status:read the integration result for a change from origin'
18 'ready:mark a head of a branch ready as a new version of its change'
19 'unready:make a ready change a draft'
20 'withdraw:mark a ready change or a draft withdrawn'
21 'checks:print the checks a change owes under the composed policy'
22 'tail:watch bus events scroll by'
23 'replay:publish ref-updated events for the current refs of a repo'
24 'help:show help'
25 )
26 _describe -t verbs 'valley verb' verbs
27 elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then
28 _files -/
29 elif [[ ${words[2]} == checks && ${words[CURRENT-1]} == --cost ]]; then
30 compadd quick slow
31 elif [[ ${words[2]} == checks && ${words[CURRENT]} == -* ]]; then
32 local -a opts=(
33 '--schema:the policy schema to compose against'
34 '--instance:the instance policy layer directory'
35 '--project:the project policy layer directory'
36 '--names:print only the owed check names, one per line'
37 '--cost:with --names, only the quick or the slow checks'
38 )
39 _describe -t options 'valley checks option' opts
40 elif [[ ${words[2]} == ready && ${words[CURRENT]} == -* ]]; then
41 local -a opts=(
42 '--head:the head to mark ready, already on origin'
43 '--change:the change ID to record the version under'
44 '--stamp:carry the change ID in the head as a Change-Id trailer'
45 )
46 _describe -t options 'valley ready option' opts
47 elif [[ ${words[2]} == ready && ${words[CURRENT-1]} == --(head|change) ]]; then
48 return
49 elif [[ ${words[2]} == pending && ${words[CURRENT]} == -* ]]; then
50 local -a opts=(
51 '--all:every project the serving host publishes'
52 '--repo:that one project'
53 '--owes:the checks each change owes, by cost'
54 '--json:print valley-pending/v1 JSON'
55 )
56 _describe -t options 'valley pending option' opts
57 elif [[ ${words[2]} == changes && ${words[CURRENT]} == -* ]]; then
58 local -a opts=(
59 '--json:print valley-changes/v1 JSON'
60 '--all:every project the serving host publishes'
61 '--repo:that one project'
62 )
63 _describe -t options 'valley changes option' opts
64 elif [[ ${words[2]} == status && ${words[CURRENT]} == -* ]]; then
65 local -a opts=('--json:print the status as one valley-status/v1 JSON object')
66 _describe -t options 'valley status option' opts
67 elif [[ ${words[2]} == (review|approve|rebase|status|ready) ]] \
68 && { (( CURRENT == 3 )) || [[ ${words[2]} == (status|ready) ]]; }; then
69 # Cached topic branches on origin. Review, approve, rebase and ready filter
70 # out merged branches; status needs those too. Silent outside a git
71 # repo — no errors mid-typing.
72 local -a branches selection
73 selection=()
74 [[ ${words[2]} != status ]] && selection=(--no-merged=origin/main)
75 branches=(${(f)"$(git for-each-ref refs/remotes/origin \
76 --format='%(refname)' "${selection[@]}" 2>/dev/null)"})
77 branches=(${branches:#refs/remotes/origin/HEAD})
78 branches=(${branches:#refs/remotes/origin/main})
79 branches=(${branches#refs/remotes/origin/})
80 (( ${#branches} )) && compadd -a branches
81 fi
82}
83
84_valley "$@"