Skip to content

Commit 8141c22

Browse files
committed
fix rubocop offenses
1 parent 207eb89 commit 8141c22

10 files changed

Lines changed: 51 additions & 35 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ source 'https://rubygems.org'
22

33
group :development do
44
# gem 'debug'
5+
gem 'completely'
56
gem 'rspec'
67
gem 'rspec_approvals'
78
gem 'runfile', require: false
89
gem 'runfile-tasks', require: false
910
gem 'simplecov'
10-
gem 'completely'
1111
end
1212

1313
gemspec

lib/bashly.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Bashly
1212
]
1313

1414
autoloads 'bashly/concerns', %i[
15-
AssetHelper Renderable ValidationHelpers
15+
AssetHelper Renderable SettingsCompletions ValidationHelpers
1616
]
1717

1818
module Script
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Bashly
2+
module SettingsCompletions
3+
COMPLETION_SHELLS = %w[bash zsh].freeze
4+
5+
def completions
6+
@completions ||= get :completions
7+
end
8+
9+
def completions?
10+
completions == 'minimal' || completion_shells.any?
11+
end
12+
13+
def completion_shells
14+
case completions
15+
when nil, false, 'minimal' then []
16+
when 'full' then COMPLETION_SHELLS
17+
when String then validate_completion_shells completions
18+
else invalid_completions
19+
end
20+
end
21+
22+
private
23+
24+
def validate_completion_shells(value)
25+
shells = value.split(',', -1).map(&:strip)
26+
valid = shells.any? && (shells - COMPLETION_SHELLS).empty?
27+
return shells if valid && shells.uniq == shells
28+
29+
invalid_completions
30+
end
31+
32+
def invalid_completions
33+
raise ConfigurationError,
34+
"completions must be false, minimal, full, or a comma-separated list of: #{COMPLETION_SHELLS.join ', '}"
35+
end
36+
end
37+
end

lib/bashly/config_validator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Bashly
22
class ConfigValidator
33
include ValidationHelpers
44

5+
COMPLETION_OPTIONS = %w[files directories no-space].freeze
6+
57
attr_reader :data
68

79
def initialize(data)
@@ -97,7 +99,7 @@ def assert_completions(key, value)
9799
assert_array "#{key}.options", value['options'], of: :string
98100

99101
Array(value['options']).each do |option|
100-
assert %w[files directories no-space].include?(option),
102+
assert COMPLETION_OPTIONS.include?(option),
101103
"#{key}.options contains an unknown option: #{option}"
102104
end
103105
end

lib/bashly/settings.rb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module Bashly
22
class Settings
3-
COMPLETION_SHELLS = %w[bash zsh].freeze
3+
COMPLETION_SHELLS = SettingsCompletions::COMPLETION_SHELLS
44

55
class << self
66
include AssetHelper
7+
include SettingsCompletions
78

89
attr_writer(
910
:argfile_var,
@@ -52,28 +53,6 @@ def compact_short_flags
5253
@compact_short_flags ||= get :compact_short_flags
5354
end
5455

55-
def completions
56-
@completions ||= get :completions
57-
end
58-
59-
def completions?
60-
completions == 'minimal' || completion_shells.any?
61-
end
62-
63-
def completion_shells
64-
value = completions
65-
return [] if value.nil? || value == false || value == 'minimal'
66-
return COMPLETION_SHELLS if value == 'full'
67-
68-
shells = value.split(',', -1).map(&:strip) if value.is_a? String
69-
valid = shells&.any? && shells.all? { |shell| COMPLETION_SHELLS.include? shell }
70-
unique = shells&.uniq == shells
71-
return shells if valid && unique
72-
73-
raise ConfigurationError,
74-
"completions must be false, minimal, full, or a comma-separated list of: #{COMPLETION_SHELLS.join ', '}"
75-
end
76-
7756
def conjoined_flag_args
7857
@conjoined_flag_args ||= get :conjoined_flag_args
7958
end

spec/bashly/commands/completions_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@
1717
.to output(completions_script).to_stdout
1818
end
1919
end
20-
2120
end

spec/bashly/integration/completion_script_bash_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def complete_with_bash(*words, trace_options: false)
1919
)
2020
end
2121

22-
context 'generation' do
22+
context 'when generating the script' do
2323
let(:cli) { File.expand_path 'spec/tmp/cli' }
2424

2525
before(:context) do
@@ -66,7 +66,7 @@ def complete_with_bash(*words, trace_options: false)
6666
end
6767
end
6868

69-
context 'configured options' do
69+
context 'with configured options' do
7070
before(:context) do
7171
Settings.completions = 'full'
7272
reset_tmp_dir

spec/bashly/integration/completion_script_zsh_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def complete_with_zsh(*words, trace_files: false)
4444
)
4545
end
4646

47-
context 'generation' do
47+
context 'when generating the script' do
4848
let(:cli) { File.expand_path 'spec/tmp/cli' }
4949

5050
before(:context) do
@@ -87,7 +87,7 @@ def complete_with_zsh(*words, trace_files: false)
8787
end
8888
end
8989

90-
context 'configured options' do
90+
context 'with configured options' do
9191
before(:context) do
9292
Settings.completions = 'full'
9393
reset_tmp_dir

spec/bashly/integration/runtime_completions_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
workspaces.each do |workspace|
55
context File.basename(workspace) do
66
examples = YAML.trusted_load_file "#{workspace}/examples.yml"
7-
cli = File.expand_path 'spec/tmp/cli'
7+
let(:cli) { File.expand_path 'spec/tmp/cli' }
88

99
before(:context) do
1010
Settings.completions = 'minimal'
@@ -24,7 +24,7 @@
2424

2525
examples.each do |name, example|
2626
describe name do
27-
it 'works' do
27+
it 'returns the expected completions' do
2828
stdout, stderr, status = Open3.capture3(
2929
cli, '__complete', *example['words']
3030
)
@@ -38,5 +38,4 @@
3838
end
3939
end
4040
end
41-
4241
end

spec/bashly/library_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
it 'delegates the request to the custom handler' do
2626
expect(subject.files).to contain_exactly(
27-
path: 'spec/tmp/src/help_command.sh',
27+
path: 'spec/tmp/src/help_command.sh',
2828
content: include('help_function=download_usage')
2929
)
3030
end

0 commit comments

Comments
 (0)