Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ source 'https://rubygems.org'

gem 'byebug'
gem 'lp'
gem 'rentacop'
gem 'rspec'
gem 'rspec_approvals'
gem 'runfile'
Expand Down
6 changes: 3 additions & 3 deletions lib/completely/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def actions
end

def prefix
text.split[0]
text.split(/ |\*/).first
end

def case_string
if text_without_prefix.empty?
'*'
elsif text_without_prefix.include? '*'
%['#{text_without_prefix.gsub '*', "'*'"}']
text_without_prefix.gsub(/([^*]+)/, "'\\1'")
else
"'#{text_without_prefix}'*"
end
end

def text_without_prefix
@text_without_prefix ||= text.split[1..].join ' '
@text_without_prefix ||= text[/^#{prefix}\s*(.*)/, 1]
end

def compgen
Expand Down
27 changes: 25 additions & 2 deletions spec/completely/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ftp:
expected: [download]

- compline: "ftp download "
expected: [another-dir, dir with spaces, dummy-dir, file with spaces.txt, ftp.yaml, gradual.yaml]
expected: [another-dir, dir with spaces, dummy-dir, file with spaces.txt, ftp.yaml, gradual.yaml, wildcard.yaml]

- compline: "ftp download -"
expected: [--help, --override]
Expand Down Expand Up @@ -70,4 +70,27 @@ gradual:
expected: [blue, red]

- compline: "cli command subcommand anything --color gr"
expected: [gray, green]
expected: [gray, green]

wildcard:
- compline: "wildcard "
expected: [download, upload]

- compline: "wildcard d"
expected: [download]

- compline: "wildcard --"
expected: [--debug, --env]

- compline: "wildcard download --"
expected: [--confirm, --contest]

- compline: "wildcard --env "
expected: [dev, prod]

- compline: "wildcard --env prod download --contest "
expected: [everything, nothing]

- compline: "wildcard download --contest "
expected: [everything, nothing]

36 changes: 34 additions & 2 deletions spec/completely/pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,25 @@
end

describe '#prefix' do
it 'returns the first word from text' do
it 'returns the first word of the pattern' do
expect(subject.prefix).to eq 'git'
end

context 'when the pattern includes a * right after the first word' do
let(:text) { 'git*--checkout' }

it 'returns the first word of the pattern' do
expect(subject.prefix).to eq 'git'
end
end

context 'when the pattern includes a * anywhere else' do
let(:text) { 'git --checkout*something' }

it 'returns the first word of the pattern' do
expect(subject.prefix).to eq 'git'
end
end
end

describe '#case_string' do
Expand All @@ -68,9 +84,25 @@
end

describe '#text_without_prefix' do
it 'returns all but the first word from text' do
it 'returns all but the first word' do
expect(subject.text_without_prefix).to eq 'commit'
end

context 'when the pattern includes a * right after the first word' do
let(:text) { 'git*--checkout' }

it 'returns all but the first word' do
expect(subject.text_without_prefix).to eq '*--checkout'
end
end

context 'when the pattern includes a * anywhere else' do
let(:text) { 'git --checkout*something' }

it 'returns all but the first word' do
expect(subject.text_without_prefix).to eq '--checkout*something'
end
end
end

describe '#compgen' do
Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/integration/wildcard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
wildcard:
- --debug
- --env
- download
- upload

wildcard*--env:
- prod
- dev

wildcard*download:
- --confirm
- --contest

wildcard*download*--contest:
- everything
- nothing