Skip to content

Commit d120d40

Browse files
committed
Add make completions
1 parent c765094 commit d120d40

File tree

7 files changed

+131
-70
lines changed

7 files changed

+131
-70
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,16 @@ jobs:
9898
run: cargo check --workspace --all-targets --all-features
9999
- name: Run cargo check with rustls-tls feature
100100
run: cargo check --workspace --all-targets --no-default-features --features rustls-tls
101+
102+
check-completions:
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v6
106+
- uses: dtolnay/rust-toolchain@stable
107+
- uses: Swatinem/rust-cache@v2
108+
- name: Build binary
109+
run: cargo build
110+
# Shell completions are generated from the CLI help output and should be
111+
# platform-independent. We only test on Linux to keep things simple.
112+
- name: Check all completions are up to date
113+
run: ./scripts/check-completions.sh

.github/workflows/test-completions.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ clean: ## Clean up build artifacts
2626
build: ## Build Rust code locally
2727
cargo build
2828

29+
.PHONY: completions
30+
completions: ## Update shell completions
31+
@echo "Building release binary..."
32+
@cargo build --release
33+
@echo "Generating completions..."
34+
@target/release/lychee --generate complete-bash > lychee-bin/complete/lychee.bash
35+
@target/release/lychee --generate complete-elvish > lychee-bin/complete/lychee.elv
36+
@target/release/lychee --generate complete-fish > lychee-bin/complete/lychee.fish
37+
@target/release/lychee --generate complete-powershell > lychee-bin/complete/_lychee.ps1
38+
@target/release/lychee --generate complete-zsh > lychee-bin/complete/_lychee
39+
@echo "✓ All completions updated in lychee-bin/complete/"
40+
2941
.PHONY: install
3042
install: ## Install project locally
3143
cargo install --path lychee-bin --locked

lychee-bin/complete/_lychee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ _lychee() {
6464
'--mode=[Set the output display mode. Determines how results are presented in the terminal]:MODE:(plain color emoji task)' \
6565
'-f+[Output format of final status report]:FORMAT:(compact detailed json markdown raw)' \
6666
'--format=[Output format of final status report]:FORMAT:(compact detailed json markdown raw)' \
67-
'--generate=[Generate special output (e.g. the man page) instead of performing link checking]:GENERATE:(man complete-bash complete-zsh complete-fish)' \
67+
'--generate=[Generate special output (e.g. the man page) instead of performing link checking]:GENERATE:(man complete-bash complete-elvish complete-fish complete-powershell complete-zsh)' \
6868
'--cookie-jar=[Read and write cookies using the given file]:COOKIE_JAR:_files' \
6969
'-p+[Preprocess input files]:COMMAND:_default' \
7070
'--preprocess=[Preprocess input files]:COMMAND:_default' \

lychee-bin/complete/lychee.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ _lychee() {
226226
return 0
227227
;;
228228
--generate)
229-
COMPREPLY=($(compgen -W "man complete-bash complete-zsh complete-fish" -- "${cur}"))
229+
COMPREPLY=($(compgen -W "man complete-bash complete-elvish complete-fish complete-powershell complete-zsh" -- "${cur}"))
230230
return 0
231231
;;
232232
--cookie-jar)

lychee-bin/complete/lychee.fish

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ markdown\t''
4646
raw\t''"
4747
complete -c lychee -l generate -d 'Generate special output (e.g. the man page) instead of performing link checking' -r -f -a "man\t''
4848
complete-bash\t''
49-
complete-zsh\t''
50-
complete-fish\t''"
49+
complete-elvish\t''
50+
complete-fish\t''
51+
complete-powershell\t''
52+
complete-zsh\t''"
5153
complete -c lychee -l cookie-jar -d 'Read and write cookies using the given file' -r -F
5254
complete -c lychee -s p -l preprocess -d 'Preprocess input files' -r
5355
complete -c lychee -s v -l verbose -d 'Set verbosity level; more output per occurrence (e.g. `-v` or `-vv`)'

scripts/check-completions.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Colors
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
NC='\033[0m' # No Color
9+
10+
LYCHEE="${TARGET_DIR:-target}/release/lychee"
11+
[[ -e "$LYCHEE" ]] || LYCHEE="${LYCHEE/%\/release\/lychee/\/debug\/lychee}"
12+
13+
if [[ ! -e "$LYCHEE" ]]; then
14+
echo -e "${RED}Error: lychee binary not found at $LYCHEE${NC}" >&2
15+
exit 1
16+
fi
17+
18+
echo "Testing completions for: $LYCHEE"
19+
echo
20+
21+
# Get all options from help
22+
HELP_OPTIONS=$(
23+
"$LYCHEE" --help |
24+
grep -E '^\s+--?[a-z0-9]' |
25+
grep -oE -- '--[a-z0-9-]+' |
26+
sort -u
27+
)
28+
29+
# Track if any check failed
30+
FAILED=false
31+
32+
check_completion() {
33+
local shell=$1
34+
local file=$2
35+
36+
echo -n "Checking $shell completion... "
37+
38+
if [[ ! -f "$file" ]]; then
39+
echo -e "${RED}FAIL${NC} - File not found"
40+
FAILED=true
41+
return
42+
fi
43+
44+
if [[ ! -s "$file" ]]; then
45+
echo -e "${RED}FAIL${NC} - File is empty"
46+
FAILED=true
47+
return
48+
fi
49+
50+
# Check for missing options
51+
local missing_opts=()
52+
while IFS= read -r opt; do
53+
local opt_name="${opt#--}"
54+
55+
# Fish uses -l option_name format, others use --option-name
56+
if [[ "$shell" == "Fish" ]]; then
57+
if ! grep -qE -- "-l ${opt_name}\\b" "$file"; then
58+
missing_opts+=("$opt")
59+
fi
60+
else
61+
if ! grep -qF -- "$opt" "$file"; then
62+
missing_opts+=("$opt")
63+
fi
64+
fi
65+
done <<< "$HELP_OPTIONS"
66+
67+
if ((${#missing_opts[@]} > 0)); then
68+
echo -e "${RED}FAIL${NC} - Missing ${#missing_opts[@]} option(s)"
69+
printf ' %s\n' "${missing_opts[@]}" | head -5
70+
if ((${#missing_opts[@]} > 5)); then
71+
echo " ..."
72+
fi
73+
FAILED=true
74+
else
75+
echo -e "${GREEN}OK${NC}"
76+
fi
77+
}
78+
79+
# Check each completion file
80+
check_completion "Bash" "lychee-bin/complete/lychee.bash"
81+
check_completion "Elvish" "lychee-bin/complete/lychee.elv"
82+
check_completion "Fish" "lychee-bin/complete/lychee.fish"
83+
check_completion "PowerShell" "lychee-bin/complete/_lychee.ps1"
84+
check_completion "Zsh" "lychee-bin/complete/_lychee"
85+
86+
echo
87+
88+
if $FAILED; then
89+
echo -e "${RED}FAILED${NC}"
90+
echo
91+
echo "Completions are out of sync with --help options."
92+
echo "To update all completion files, run:"
93+
echo
94+
echo -e " ${GREEN}make completions${NC}"
95+
echo
96+
exit 1
97+
else
98+
echo -e "${GREEN}All checks passed${NC}"
99+
exit 0
100+
fi

0 commit comments

Comments
 (0)