Skip to content

Commit 21bc5d4

Browse files
committed
add complete_options specs
1 parent 690c264 commit 21bc5d4

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# mygit completion -*- shell-script -*-
2+
3+
# This bash completions script was generated by
4+
# completely (https://github.com/dannyben/completely)
5+
# Modifying it manually is not recommended
6+
7+
_mygit_completions_filter() {
8+
local words="$1"
9+
local cur=${COMP_WORDS[COMP_CWORD]}
10+
local result=()
11+
12+
if [[ "${cur:0:1}" == "-" ]]; then
13+
echo "$words"
14+
15+
else
16+
for word in $words; do
17+
[[ "${word:0:1}" != "-" ]] && result+=("$word")
18+
done
19+
20+
echo "${result[*]}"
21+
22+
fi
23+
}
24+
25+
_mygit_completions() {
26+
local cur=${COMP_WORDS[COMP_CWORD]}
27+
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
28+
local compline="${compwords[*]}"
29+
30+
case "$compline" in
31+
*)
32+
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "status commit")" -- "$cur")
33+
;;
34+
35+
esac
36+
} &&
37+
complete -o nosort -F _mygit_completions mygit
38+
39+
# ex: filetype=sh

spec/completely/completions_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
.except(/case.*/m)
5050
end
5151
end
52+
53+
context 'with a configuration file that includes complete_options' do
54+
let(:file) { 'complete_options' }
55+
56+
it 'adds the complete_options to the complete_command' do
57+
expect(subject.script).to match_approval 'completions/script-complete-options'
58+
end
59+
end
5260
end
5361

5462
describe '#wrapper_function' do

spec/completely/config_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,20 @@
99
expect(subject.flat_config.to_yaml).to match_approval('config/flat_config')
1010
end
1111
end
12+
13+
context 'when complete_options is defined' do
14+
let(:file) { 'complete_options' }
15+
16+
describe 'config' do
17+
it 'ignores the completely_config YAML key' do
18+
expect(subject.config.keys).to eq ["mygit"]
19+
end
20+
end
21+
22+
describe 'options' do
23+
it 'returns complete_options from the YAML file' do
24+
expect(subject.options[:complete_options]).to eq '-o nosort'
25+
end
26+
end
27+
end
1228
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
completely_options:
2+
complete_options: -o nosort
3+
4+
mygit:
5+
- status
6+
- commit

0 commit comments

Comments
 (0)