Skip to content

Commit 57601ca

Browse files
authored
Merge pull request #8886 from jonbarlo/feature/default-cli-command
[feature] default_cli_command for config what command bundler runs when no specific command is provided
2 parents f1cf945 + 0ecbfad commit 57601ca

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

bundler/lib/bundler/settings.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Settings
5959
bin
6060
cache_path
6161
console
62+
default_cli_command
6263
gem.ci
6364
gem.github_username
6465
gem.linter

bundler/lib/bundler/settings/validator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ def self.validate!(key, value, settings)
7474
fail!(key, value, "`#{other_key}` is current set to #{other_setting.inspect}", "the `#{conflicting.join("`, `")}` groups conflict")
7575
end
7676
end
77+
78+
rule %w[default_cli_command], "default_cli_command must be either 'install' or 'cli_help'" do |key, value, _settings|
79+
valid_values = %w[install cli_help]
80+
if !value.nil? && !valid_values.include?(value.to_s)
81+
fail!(key, value, "must be one of: #{valid_values.join(", ")}")
82+
end
83+
end
7784
end
7885
end
7986
end

spec/bundler/settings_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,25 @@
351351
expect(settings["mirror.https://rubygems.org/"]).to eq("http://example-mirror.rubygems.org")
352352
end
353353
end
354+
355+
describe "default_cli_command validation" do
356+
it "accepts 'install' as a valid value" do
357+
expect { settings.set_local("default_cli_command", "install") }.not_to raise_error
358+
end
359+
360+
it "accepts 'cli_help' as a valid value" do
361+
expect { settings.set_local("default_cli_command", "cli_help") }.not_to raise_error
362+
end
363+
364+
it "rejects invalid values" do
365+
expect { settings.set_local("default_cli_command", "invalid") }.to raise_error(
366+
Bundler::InvalidOption,
367+
/Setting `default_cli_command` to "invalid" failed:\n - default_cli_command must be either 'install' or 'cli_help'\n - must be one of: install, cli_help/
368+
)
369+
end
370+
371+
it "accepts nil values" do
372+
expect { settings.set_local("default_cli_command", nil) }.not_to raise_error
373+
end
374+
end
354375
end

0 commit comments

Comments
 (0)