mirror of
https://github.com/casey/just.git
synced 2024-11-22 10:26:26 +03:00
Compare commits
2 Commits
76bda4cfd9
...
7680b19979
Author | SHA1 | Date | |
---|---|---|---|
|
7680b19979 | ||
|
7f7275550d |
1
.github/workflows/ci.yaml
vendored
1
.github/workflows/ci.yaml
vendored
@ -66,6 +66,7 @@ jobs:
|
||||
run: |
|
||||
./bin/generate-completions
|
||||
git diff --no-ext-diff --quiet --exit-code
|
||||
./tests/completions/just.bash
|
||||
|
||||
- name: Check for Forbidden Words
|
||||
if: ${{ matrix.os == 'ubuntu-latest' }}
|
||||
|
@ -25,7 +25,14 @@ _just() {
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
elif [[ ${COMP_CWORD} -eq 1 ]]; then
|
||||
local recipes=$(just --summary --color never 2> /dev/null)
|
||||
local recipes=$(just --summary 2> /dev/null)
|
||||
|
||||
if echo "${cur}" | grep -qF '/'; then
|
||||
local path_prefix=$(echo "${cur}" | sed 's/[/][^/]*$/\//')
|
||||
local recipes=$(just --summary 2> /dev/null -- "${path_prefix}")
|
||||
local recipes=$(printf "${path_prefix}%s\t" $recipes)
|
||||
fi
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
|
||||
return 0
|
||||
|
3
justfile
3
justfile
@ -170,6 +170,9 @@ watch-readme:
|
||||
generate-completions:
|
||||
./bin/generate-completions
|
||||
|
||||
test-completions:
|
||||
./tests/completions/just.bash
|
||||
|
||||
build-book:
|
||||
cargo run --package generate-book
|
||||
mdbook build book/en
|
||||
|
@ -166,7 +166,14 @@ pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
elif [[ ${COMP_CWORD} -eq 1 ]]; then
|
||||
local recipes=$(just --summary --color never 2> /dev/null)
|
||||
local recipes=$(just --summary 2> /dev/null)
|
||||
|
||||
if echo "${cur}" | grep -qF '/'; then
|
||||
local path_prefix=$(echo "${cur}" | sed 's/[/][^/]*$/\//')
|
||||
local recipes=$(just --summary 2> /dev/null -- "${path_prefix}")
|
||||
local recipes=$(printf "${path_prefix}%s\t" $recipes)
|
||||
fi
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
|
||||
return 0
|
||||
|
63
tests/completions/just.bash
Executable file
63
tests/completions/just.bash
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# --- Shared functions ---
|
||||
reply_equals() {
|
||||
local reply=$(declare -p COMPREPLY)
|
||||
local expected=$1
|
||||
|
||||
if [ "$reply" = "$expected" ]; then
|
||||
echo "${FUNCNAME[1]}: ok"
|
||||
else
|
||||
exit_code=1
|
||||
echo >&2 "${FUNCNAME[1]}: failed! Completion for \`${COMP_WORDS[*]}\` does not match."
|
||||
|
||||
echo
|
||||
diff -U3 --label expected <(echo "$expected") --label actual <(echo "$reply") >&2
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Initial Setup ---
|
||||
source ./completions/just.bash
|
||||
cd tests/completions
|
||||
cargo build
|
||||
PATH="$(git rev-parse --show-toplevel)/target/debug:$PATH"
|
||||
exit_code=0
|
||||
|
||||
# --- Tests ---
|
||||
test_complete_all_recipes() {
|
||||
COMP_WORDS=(just)
|
||||
COMP_CWORD=1 _just just
|
||||
reply_equals 'declare -a COMPREPLY=([0]="deploy" [1]="install" [2]="publish" [3]="push" [4]="test")'
|
||||
}
|
||||
test_complete_all_recipes
|
||||
|
||||
test_complete_recipes_starting_with_i() {
|
||||
COMP_WORDS=(just i)
|
||||
COMP_CWORD=1 _just just
|
||||
reply_equals 'declare -a COMPREPLY=([0]="install")'
|
||||
}
|
||||
test_complete_recipes_starting_with_i
|
||||
|
||||
test_complete_recipes_starting_with_p() {
|
||||
COMP_WORDS=(just p)
|
||||
COMP_CWORD=1 _just just
|
||||
reply_equals 'declare -a COMPREPLY=([0]="publish" [1]="push")'
|
||||
}
|
||||
test_complete_recipes_starting_with_p
|
||||
|
||||
test_complete_recipes_from_subdirs() {
|
||||
COMP_WORDS=(just subdir/)
|
||||
COMP_CWORD=1 _just just
|
||||
reply_equals 'declare -a COMPREPLY=([0]="subdir/special" [1]="subdir/surprise")'
|
||||
}
|
||||
test_complete_recipes_from_subdirs
|
||||
|
||||
# --- Conclusion ---
|
||||
if [ $exit_code = 0 ]; then
|
||||
echo "All tests passed."
|
||||
else
|
||||
echo "Some test[s] failed."
|
||||
fi
|
||||
|
||||
exit $exit_code
|
5
tests/completions/justfile
Executable file
5
tests/completions/justfile
Executable file
@ -0,0 +1,5 @@
|
||||
install:
|
||||
test:
|
||||
deploy:
|
||||
push:
|
||||
publish:
|
2
tests/completions/subdir/justfile
Executable file
2
tests/completions/subdir/justfile
Executable file
@ -0,0 +1,2 @@
|
||||
special:
|
||||
surprise:
|
Loading…
Reference in New Issue
Block a user