Skip to content

Commit 44c00a1

Browse files
committed
- Add COMPLETELY_DEBUG environment setting
1 parent 8d25207 commit 44c00a1

File tree

10 files changed

+54
-1
lines changed

10 files changed

+54
-1
lines changed

lib/completely/commands/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def config_path_usage
1212
def function_usage
1313
option "-f --function NAME", "Modify the name of the function in the generated script"
1414
end
15+
16+
def debug_usage
17+
environment "COMPLETELY_DEBUG", "It not empty, the generated script will include an additional debugging snippet that outputs the compline and current word to a text file when a completion is requested"
18+
end
1519
end
1620

1721
protected

lib/completely/commands/generate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Generate < Base
1313

1414
config_path_usage
1515
param "OUTPUT_PATH", "Path to the output bash script [default: completely.bash]"
16+
debug_usage
1617

1718
def run
1819
wrap = args['--wrap']

lib/completely/commands/preview.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Preview < Base
1010

1111
function_usage
1212
config_path_usage
13+
debug_usage
1314

1415
def run
1516
puts script

lib/completely/commands/test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Test < Base
2121
environment "COMPLETELY_CONFIG_PATH", "Path to a completely configuration file [default: completely.yaml]"
2222
environment "COMPLETELY_SCRIPT_PATH", "Path to a completions script. When set, this script will be tested instead of the completely configuration file"
2323
environment "COMPLETELY_SCRIPT_FUNCTION", "The main completion function to call when using a custom script. If not set, the basename of the script path will be used, prefixed by an underscore"
24+
debug_usage
2425

2526
example %q[completely test "mygit pu"]
2627
example %q[completely test "mygit pull "]

spec/approvals/cli/generate/help

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ Parameters:
2121

2222
OUTPUT_PATH
2323
Path to the output bash script [default: completely.bash]
24+
25+
Environment Variables:
26+
COMPLETELY_DEBUG
27+
It not empty, the generated script will include an additional debugging
28+
snippet that outputs the compline and current word to a text file when a
29+
completion is requested

spec/approvals/cli/preview/help

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ Options:
1414
Parameters:
1515
CONFIG_PATH
1616
Path to the YAML configuration file [default: completely.yaml]
17+
18+
Environment Variables:
19+
COMPLETELY_DEBUG
20+
It not empty, the generated script will include an additional debugging
21+
snippet that outputs the compline and current word to a text file when a
22+
completion is requested

spec/approvals/cli/test/help

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Environment Variables:
3737
The main completion function to call when using a custom script. If not set,
3838
the basename of the script path will be used, prefixed by an underscore
3939

40+
COMPLETELY_DEBUG
41+
It not empty, the generated script will include an additional debugging
42+
snippet that outputs the compline and current word to a text file when a
43+
completion is requested
44+
4045
Examples:
4146
completely test "mygit pu"
4247
completely test "mygit pull "
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# completely 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+
_completely_completions() {
8+
local cur compline
9+
_init_completion -s || return
10+
cur=${COMP_WORDS[COMP_CWORD]}
11+
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
12+
13+
if [[ -n "$COMPLETELY_DEBUG" ]]; then
14+
echo "compline: '$compline'" > 'completely-debug.txt'
15+
echo "cur: '$cur'" >> 'completely-debug.txt'
16+
fi
17+
18+
...

spec/completely/completions_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
expect(subject.script).to match_approval "completions/script-only-spaces"
4141
end
4242
end
43+
44+
context "when COMPLETELY_DEBUG is set", :focus do
45+
before { ENV['COMPLETELY_DEBUG'] = '1' }
46+
after { ENV['COMPLETELY_DEBUG'] = nil }
47+
48+
it "adds an additional debug snippet to the script" do
49+
expect(subject.script).to match_approval("completions/script-with-debug")
50+
.except(/case.*/m)
51+
52+
end
53+
end
4354
end
4455

4556
describe '#wrapper_function' do

spec/completely/pattern_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
end
4444
end
4545

46-
describe '#case_string', :focus do
46+
describe '#case_string' do
4747
it "returns the quoted pattern (excluding command name) with a wildcard suffix" do
4848
expect(subject.case_string).to eq "'commit'*"
4949
end

0 commit comments

Comments
 (0)