gunk-dev/the-valley

_valley

source2be9421c0777main's published tip history
3.2 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 branches on origin not merged into origin/main'
13 'review:page through a branch, then approve, reject, or skip'
14 'approve:approve a change without paging it, filing its integration request'
15 'rebase:rebase a change onto origin/main and push it with a lease'
16 'status:read the integration result for a change from origin'
17 'ready:mark a head of a branch ready as a new version of its change'
18 'unready:make a ready change a draft'
19 'withdraw:mark a ready change or a draft withdrawn'
20 'checks:print the checks a change owes under the composed policy'
21 'tail:watch bus events scroll by'
22 'replay:publish ref-updated events for the current refs of a repo'
23 'help:show help'
24 )
25 _describe -t verbs 'valley verb' verbs
26 elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then
27 _files -/
28 elif [[ ${words[2]} == checks && ${words[CURRENT-1]} == --cost ]]; then
29 compadd quick slow
30 elif [[ ${words[2]} == checks && ${words[CURRENT]} == -* ]]; then
31 local -a opts=(
32 '--schema:the policy schema to compose against'
33 '--instance:the instance policy layer directory'
34 '--project:the project policy layer directory'
35 '--names:print only the owed check names, one per line'
36 '--cost:with --names, only the quick or the slow checks'
37 )
38 _describe -t options 'valley checks option' opts
39 elif [[ ${words[2]} == ready && ${words[CURRENT]} == -* ]]; then
40 local -a opts=(
41 '--head:the head to mark ready, already on origin'
42 '--change:the change ID to record the version under'
43 '--stamp:carry the change ID in the head as a Change-Id trailer'
44 )
45 _describe -t options 'valley ready option' opts
46 elif [[ ${words[2]} == ready && ${words[CURRENT-1]} == --(head|change) ]]; then
47 return
48 elif [[ ${words[2]} == status && ${words[CURRENT]} == -* ]]; then
49 local -a opts=('--json:print the status as one valley-status/v1 JSON object')
50 _describe -t options 'valley status option' opts
51 elif [[ ${words[2]} == (review|approve|rebase|status|ready) ]] \
52 && { (( CURRENT == 3 )) || [[ ${words[2]} == (status|ready) ]]; }; then
53 # Cached topic branches on origin. Review, approve, rebase and ready filter
54 # out merged branches; status needs those too. Silent outside a git
55 # repo — no errors mid-typing.
56 local -a branches selection
57 selection=()
58 [[ ${words[2]} != status ]] && selection=(--no-merged=origin/main)
59 branches=(${(f)"$(git for-each-ref refs/remotes/origin \
60 --format='%(refname)' "${selection[@]}" 2>/dev/null)"})
61 branches=(${branches:#refs/remotes/origin/HEAD})
62 branches=(${branches:#refs/remotes/origin/main})
63 branches=(${branches#refs/remotes/origin/})
64 (( ${#branches} )) && compadd -a branches
65 fi
66}
67
68_valley "$@"