gunk-dev/the-valley

valley-cli.sh

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