gunk-dev/the-valley

valley-cli.sh

source6a7605f70901main's published tip history
2.8 KiB
1# shellcheck shell=bash
2# Paths and fixtures come from the derivation environment.
3# shellcheck disable=SC2154
4shellcheck "$bashCompletion"
5# The linter cannot read zsh; a bare parse is the cheap check.
6zsh -n "$zshCompletion"
7# The completion turns the handle cache into candidates, ready changes
8# first, with the title as the description, and then the branches. _describe
9# and compadd are stubbed to print what they are given.
10repo="$PWD/completion-repo"
11git init --quiet "$repo"
12mkdir "$repo/.git/valley"
13printf 'mxrr\tready\tbump-the-valley-8770343e\tflake: bump the-valley\nhttp:abcd\tdraft\t\tno branch\n' > "$repo/.git/valley/handles"
14git -C "$repo" update-ref refs/remotes/origin/topic HEAD 2>/dev/null || true
15cat > complete.zsh <<'ZSH'
16_describe() { print -r -- "describe $*"; print -rl -- "${(P@)${@[-1]}}" | sed 's/^/ /'; }
17compadd() { print -r -- "compadd $*"; }
18words=(valley review '')
19CURRENT=3
20source "$1"
21ZSH
22(cd "$repo" && zsh "$OLDPWD/complete.zsh" "$zshCompletion") > complete.out
23grep -q '^ mxrr:flake: bump the-valley$' complete.out
24grep -q '^ http\\:abcd:no branch$' complete.out
25# With no cache, the branches alone.
26rm "$repo/.git/valley/handles"
27(cd "$repo" && zsh "$OLDPWD/complete.zsh" "$zshCompletion") > complete.out
28if grep -q describe complete.out; then exit 1; fi
29valley help > help.txt
30grep -q '^usage: valley' help.txt
31test "$(wc -l < help.txt)" -le 50
32expected_verbs="ready
33unready
34withdraw
35rebase
36checks
37pending
38review
39approve
40status
41changes
42plan
43knot
44flow
45tail
46replay
47self-update
48telemetry"
49verbs="$(awk '/^ [a-z]/ { print $1 }' help.txt)"
50test "$verbs" = "$expected_verbs"
51for v in $verbs; do
52 valley help "$v" > "help-$v.txt"
53 grep -q "^usage: valley $v" "help-$v.txt"
54 # flow's help flags are valley-flow's (nix/checks/flow.nix).
55 if [ "$v" = flow ]; then continue; fi
56 valley "$v" --help > "help-$v-flag.txt"
57 cmp -s "help-$v.txt" "help-$v-flag.txt"
58 valley "$v" -h > "help-$v-short.txt"
59 cmp -s "help-$v.txt" "help-$v-short.txt"
60done
61if valley help unknown-verb > /dev/null 2> err.txt; then exit 1; fi
62grep -q 'unknown help topic: unknown-verb' err.txt
63# Both zsh and bash completions complete all 17 verbs after `valley help`.
64cat > complete-help.zsh <<'ZSH'
65_describe() { print -r -- "describe $*"; print -rl -- "${(P@)${@[-1]}}" | sed 's/^/ /'; }
66compadd() { print -r -- "compadd $*"; }
67words=(valley help '')
68CURRENT=3
69source "$1"
70ZSH
71zsh "$PWD/complete-help.zsh" "$zshCompletion" > complete-help.out
72for v in $verbs; do
73 grep -q "^ $v:" complete-help.out
74done
75complete() { :; }
76# shellcheck disable=SC2086
77compgen() { printf '%s\n' $2; }
78# shellcheck disable=SC1090
79source "$bashCompletion"
80COMP_WORDS=(valley help '')
81COMP_CWORD=2
82_valley
83for v in $verbs; do
84 printf '%s\n' "${COMPREPLY[@]}" | grep -x -- "$v" > /dev/null
85done
86test -f "$valley/share/bash-completion/completions/valley"
87test -f "$valley/share/zsh/site-functions/_valley"
88touch "$out"