1
1
mirror of https://github.com/casey/just.git synced 2024-11-26 00:24:22 +03:00

Compare commits

...

2 Commits

7 changed files with 90 additions and 2 deletions

View File

@ -66,6 +66,7 @@ jobs:
run: | run: |
./bin/generate-completions ./bin/generate-completions
git diff --no-ext-diff --quiet --exit-code git diff --no-ext-diff --quiet --exit-code
./tests/completions/just.bash
- name: Check for Forbidden Words - name: Check for Forbidden Words
if: ${{ matrix.os == 'ubuntu-latest' }} if: ${{ matrix.os == 'ubuntu-latest' }}

View File

@ -25,7 +25,14 @@ _just() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0
elif [[ ${COMP_CWORD} -eq 1 ]]; then 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 if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
return 0 return 0

View File

@ -170,6 +170,9 @@ watch-readme:
generate-completions: generate-completions:
./bin/generate-completions ./bin/generate-completions
test-completions:
./tests/completions/just.bash
build-book: build-book:
cargo run --package generate-book cargo run --package generate-book
mdbook build book/en mdbook build book/en

View File

@ -166,7 +166,14 @@ pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0
elif [[ ${COMP_CWORD} -eq 1 ]]; then 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 if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
return 0 return 0

63
tests/completions/just.bash Executable file
View 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
View File

@ -0,0 +1,5 @@
install:
test:
deploy:
push:
publish:

View File

@ -0,0 +1,2 @@
special:
surprise: