| 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 the composed policy requires of a change' |
| 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 required 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 | '--if-active:add the version only while the change is ready at this active head' |
| 45 | '--stamp:carry the change ID in the head as a Change-Id trailer' |
| 46 | ) |
| 47 | _describe -t options 'valley ready option' opts |
| 48 | elif [[ ${words[2]} == ready && ${words[CURRENT-1]} == --(head|change|if-active) ]]; then |
| 49 | return |
| 50 | elif [[ ${words[2]} == approve && ${words[CURRENT]} == -* ]]; then |
| 51 | local -a opts=('--head:the exact head to approve, one of the change'"'"'s version heads') |
| 52 | _describe -t options 'valley approve option' opts |
| 53 | elif [[ ${words[2]} == approve && ${words[CURRENT-1]} == --head ]]; then |
| 54 | return |
| 55 | elif [[ ${words[2]} == pending && ${words[CURRENT]} == -* ]]; then |
| 56 | local -a opts=( |
| 57 | '--all:every project the serving host publishes' |
| 58 | '--repo:that one project' |
| 59 | '--checks:the checks each change requires, by cost' |
| 60 | '--json:print valley-pending/v1 JSON' |
| 61 | ) |
| 62 | _describe -t options 'valley pending option' opts |
| 63 | elif [[ ${words[2]} == changes && ${words[CURRENT]} == -* ]]; then |
| 64 | local -a opts=( |
| 65 | '--json:print valley-changes/v1 JSON' |
| 66 | '--all:every project the serving host publishes' |
| 67 | '--repo:that one project' |
| 68 | ) |
| 69 | _describe -t options 'valley changes option' opts |
| 70 | elif [[ ${words[2]} == status && ${words[CURRENT]} == -* ]]; then |
| 71 | local -a opts=('--json:print the status as one valley-status/v1 JSON object') |
| 72 | _describe -t options 'valley status option' opts |
| 73 | elif [[ ${words[2]} == (review|approve|rebase|status|ready) ]] \ |
| 74 | && { (( CURRENT == 3 )) || [[ ${words[2]} == (status|ready|approve) ]]; }; then |
| 75 | # Cached topic branches on origin. Review, approve, rebase and ready filter |
| 76 | # out merged branches; status needs those too. Silent outside a git |
| 77 | # repo — no errors mid-typing. |
| 78 | local -a branches selection |
| 79 | selection=() |
| 80 | [[ ${words[2]} != status ]] && selection=(--no-merged=origin/main) |
| 81 | branches=(${(f)"$(git for-each-ref refs/remotes/origin \ |
| 82 | --format='%(refname)' "${selection[@]}" 2>/dev/null)"}) |
| 83 | branches=(${branches:#refs/remotes/origin/HEAD}) |
| 84 | branches=(${branches:#refs/remotes/origin/main}) |
| 85 | branches=(${branches#refs/remotes/origin/}) |
| 86 | (( ${#branches} )) && compadd -a branches |
| 87 | fi |
| 88 | } |
| 89 | |
| 90 | _valley "$@" |