diff --git a/bundler/lib/bundler/settings.rb b/bundler/lib/bundler/settings.rb index 81f1857eec76..8c06593bcfe8 100644 --- a/bundler/lib/bundler/settings.rb +++ b/bundler/lib/bundler/settings.rb @@ -59,6 +59,7 @@ class Settings bin cache_path console + default_cli_command gem.ci gem.github_username gem.linter diff --git a/bundler/lib/bundler/settings/validator.rb b/bundler/lib/bundler/settings/validator.rb index 9aa1627fb2e2..093e9c2b62d9 100644 --- a/bundler/lib/bundler/settings/validator.rb +++ b/bundler/lib/bundler/settings/validator.rb @@ -74,6 +74,13 @@ def self.validate!(key, value, settings) fail!(key, value, "`#{other_key}` is current set to #{other_setting.inspect}", "the `#{conflicting.join("`, `")}` groups conflict") end end + + rule %w[default_cli_command], "default_cli_command must be either 'install' or 'cli_help'" do |key, value, settings| + valid_values = %w[install cli_help] + if !value.nil? && !valid_values.include?(value.to_s) + fail!(key, value, "must be one of: #{valid_values.join(", ")}") + end + end end end end diff --git a/bundler/spec/bundler/settings_spec.rb b/bundler/spec/bundler/settings_spec.rb index 592db81e9b90..bf2b3fddb890 100644 --- a/bundler/spec/bundler/settings_spec.rb +++ b/bundler/spec/bundler/settings_spec.rb @@ -351,4 +351,28 @@ expect(settings["mirror.https://rubygems.org/"]).to eq("http://example-mirror.rubygems.org") end end + + describe "default_cli_command validation" do + it "accepts 'install' as a valid value" do + expect { settings.set_local("default_cli_command", "install") }.not_to raise_error + end + + it "accepts 'cli_help' as a valid value" do + expect { settings.set_local("default_cli_command", "cli_help") }.not_to raise_error + end + + it "rejects invalid values" do + expect { settings.set_local("default_cli_command", "invalid") }.to raise_error( + Bundler::InvalidOption, + /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/ + ) + end + + it "rejects nil values" do + expect { settings.set_local("default_cli_command", nil) }.to raise_error( + Bundler::InvalidOption, + /Setting `default_cli_command` to nil failed:\n - default_cli_command must be either 'install' or 'cli_help'\n - must be one of: install, cli_help/ + ) + end + end end