From 7354a9b0bb1e9f6f118496de8a313305bc9f0c4b Mon Sep 17 00:00:00 2001 From: Jonathan Barquero Date: Tue, 29 Jul 2025 14:15:59 -0600 Subject: [PATCH 1/6] feat: default_cli_command for config what command bundler runs when no specific command is provided. --- bundler/.bundle/config | 2 ++ bundler/lib/bundler/cli.rb | 28 ++++++----------------- bundler/lib/bundler/settings.rb | 7 ++++-- bundler/lib/bundler/settings/validator.rb | 9 ++++++++ bundler/spec/bundler/settings_spec.rb | 26 +++++++++++++++++++++ 5 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 bundler/.bundle/config diff --git a/bundler/.bundle/config b/bundler/.bundle/config new file mode 100644 index 000000000000..45b6b5a4ae95 --- /dev/null +++ b/bundler/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_DEFAULT_CLI_COMMAND: "cli_help" diff --git a/bundler/lib/bundler/cli.rb b/bundler/lib/bundler/cli.rb index b8a8be82c185..2195a2a0ffac 100644 --- a/bundler/lib/bundler/cli.rb +++ b/bundler/lib/bundler/cli.rb @@ -86,26 +86,8 @@ def initialize(*args) desc "cli_help", "Prints a summary of bundler commands", hide: true def cli_help - version - Bundler.ui.info "\n" - - primary_commands = ["install", "update", "cache", "exec", "config", "help"] - - list = self.class.printable_commands(true) - by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] } - utilities = by_name.keys.sort - primary_commands - primary_commands.map! {|name| (by_name[name] || raise("no primary command #{name}")).first } - utilities.map! {|name| by_name[name].first } - - shell.say "Bundler commands:\n\n" - - shell.say " Primary commands:\n" - shell.print_table(primary_commands, indent: 4, truncate: true) - shell.say - shell.say " Utilities:\n" - shell.print_table(utilities, indent: 4, truncate: true) - shell.say - self.class.send(:class_options_help, shell) + # Use the enhanced man-based help system for consistency + help(nil) end default_task(Bundler.settings[:default_cli_command]) @@ -489,7 +471,11 @@ def console(group = nil) def version cli_help = current_command.name == "cli_help" if cli_help || ARGV.include?("version") - build_info = " (#{BuildMetadata.timestamp} commit #{BuildMetadata.git_commit_sha})" + # Only show build info if it's not the default timestamp + timestamp = BuildMetadata.timestamp + unless timestamp == "1980-01-02" + build_info = " (#{timestamp} commit #{BuildMetadata.git_commit_sha})" + end end if !cli_help && Bundler.feature_flag.bundler_4_mode? diff --git a/bundler/lib/bundler/settings.rb b/bundler/lib/bundler/settings.rb index 81f1857eec76..5e8a10551917 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 @@ -398,13 +399,15 @@ def set_key(raw_key, value, hash, file) key = key_for(raw_key) + # Always validate, even if the value is already set + Validator.validate!(raw_key, converted_value(value, raw_key), hash) + return if hash[key] == value hash[key] = value + hash.delete(key) if value.nil? - Validator.validate!(raw_key, converted_value(value, raw_key), hash) - return unless file SharedHelpers.filesystem_access(file.dirname, :create) do |p| diff --git a/bundler/lib/bundler/settings/validator.rb b/bundler/lib/bundler/settings/validator.rb index 9aa1627fb2e2..7e1f3d240a17 100644 --- a/bundler/lib/bundler/settings/validator.rb +++ b/bundler/lib/bundler/settings/validator.rb @@ -74,6 +74,15 @@ 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? + fail!(key, value, "must be one of: #{valid_values.join(", ")}") + elsif !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..cf2466fd3881 100644 --- a/bundler/spec/bundler/settings_spec.rb +++ b/bundler/spec/bundler/settings_spec.rb @@ -351,4 +351,30 @@ expect(settings["mirror.https://rubygems.org/"]).to eq("http://example-mirror.rubygems.org") end end + + describe "default_cli_command validation" do + let(:settings) { described_class.new } + + 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 From 2b16d540c8e0779306d3f4a0202c1002fea13d01 Mon Sep 17 00:00:00 2001 From: Jonathan Barquero Date: Thu, 31 Jul 2025 14:28:29 -0600 Subject: [PATCH 2/6] fix: code refactor: removed unnecesary files, removed changes no longer required and updating rspec test to not override the settings --- .bundle/config | 2 -- bundler/lib/bundler/cli.rb | 28 ++++++++++++++++++++------- bundler/spec/bundler/settings_spec.rb | 2 -- 3 files changed, 21 insertions(+), 11 deletions(-) delete mode 100644 .bundle/config diff --git a/.bundle/config b/.bundle/config deleted file mode 100644 index 1af66845018e..000000000000 --- a/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_PATH__SYSTEM: "true" diff --git a/bundler/lib/bundler/cli.rb b/bundler/lib/bundler/cli.rb index 2195a2a0ffac..b8a8be82c185 100644 --- a/bundler/lib/bundler/cli.rb +++ b/bundler/lib/bundler/cli.rb @@ -86,8 +86,26 @@ def initialize(*args) desc "cli_help", "Prints a summary of bundler commands", hide: true def cli_help - # Use the enhanced man-based help system for consistency - help(nil) + version + Bundler.ui.info "\n" + + primary_commands = ["install", "update", "cache", "exec", "config", "help"] + + list = self.class.printable_commands(true) + by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] } + utilities = by_name.keys.sort - primary_commands + primary_commands.map! {|name| (by_name[name] || raise("no primary command #{name}")).first } + utilities.map! {|name| by_name[name].first } + + shell.say "Bundler commands:\n\n" + + shell.say " Primary commands:\n" + shell.print_table(primary_commands, indent: 4, truncate: true) + shell.say + shell.say " Utilities:\n" + shell.print_table(utilities, indent: 4, truncate: true) + shell.say + self.class.send(:class_options_help, shell) end default_task(Bundler.settings[:default_cli_command]) @@ -471,11 +489,7 @@ def console(group = nil) def version cli_help = current_command.name == "cli_help" if cli_help || ARGV.include?("version") - # Only show build info if it's not the default timestamp - timestamp = BuildMetadata.timestamp - unless timestamp == "1980-01-02" - build_info = " (#{timestamp} commit #{BuildMetadata.git_commit_sha})" - end + build_info = " (#{BuildMetadata.timestamp} commit #{BuildMetadata.git_commit_sha})" end if !cli_help && Bundler.feature_flag.bundler_4_mode? diff --git a/bundler/spec/bundler/settings_spec.rb b/bundler/spec/bundler/settings_spec.rb index cf2466fd3881..bf2b3fddb890 100644 --- a/bundler/spec/bundler/settings_spec.rb +++ b/bundler/spec/bundler/settings_spec.rb @@ -353,8 +353,6 @@ end describe "default_cli_command validation" do - let(:settings) { described_class.new } - it "accepts 'install' as a valid value" do expect { settings.set_local("default_cli_command", "install") }.not_to raise_error end From 34803e11daf19e31a8c4e037aa4d1a2ed276cc4d Mon Sep 17 00:00:00 2001 From: Jonathan Barquero Date: Sun, 10 Aug 2025 21:46:12 -0600 Subject: [PATCH 3/6] ref: undo .bundle/config files changes --- .bundle/config | 2 ++ bundler/.bundle/config | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 .bundle/config delete mode 100644 bundler/.bundle/config diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 000000000000..1af66845018e --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_PATH__SYSTEM: "true" diff --git a/bundler/.bundle/config b/bundler/.bundle/config deleted file mode 100644 index 45b6b5a4ae95..000000000000 --- a/bundler/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_DEFAULT_CLI_COMMAND: "cli_help" From 300b1d24e76f834fa5e61f25eba2f5ad541e0f11 Mon Sep 17 00:00:00 2001 From: Jonathan Barquero Date: Sun, 10 Aug 2025 22:01:24 -0600 Subject: [PATCH 4/6] fix: undo unneceasary validate! change --- bundler/lib/bundler/settings.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bundler/lib/bundler/settings.rb b/bundler/lib/bundler/settings.rb index 5e8a10551917..6324d1507823 100644 --- a/bundler/lib/bundler/settings.rb +++ b/bundler/lib/bundler/settings.rb @@ -399,15 +399,14 @@ def set_key(raw_key, value, hash, file) key = key_for(raw_key) - # Always validate, even if the value is already set - Validator.validate!(raw_key, converted_value(value, raw_key), hash) - return if hash[key] == value hash[key] = value - + hash.delete(key) if value.nil? + Validator.validate!(raw_key, converted_value(value, raw_key), hash) + return unless file SharedHelpers.filesystem_access(file.dirname, :create) do |p| From e5a13606ae131b948bfd48c34395dfd21444d43c Mon Sep 17 00:00:00 2001 From: Jonathan Barquero Date: Sun, 10 Aug 2025 22:03:36 -0600 Subject: [PATCH 5/6] fix: extra space --- bundler/lib/bundler/settings.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundler/lib/bundler/settings.rb b/bundler/lib/bundler/settings.rb index 6324d1507823..8c06593bcfe8 100644 --- a/bundler/lib/bundler/settings.rb +++ b/bundler/lib/bundler/settings.rb @@ -402,11 +402,10 @@ def set_key(raw_key, value, hash, file) return if hash[key] == value hash[key] = value - hash.delete(key) if value.nil? Validator.validate!(raw_key, converted_value(value, raw_key), hash) - + return unless file SharedHelpers.filesystem_access(file.dirname, :create) do |p| From e042f4a281cb01f71916a808b3ab9748b672201d Mon Sep 17 00:00:00 2001 From: Jonathan Barquero Date: Mon, 18 Aug 2025 12:26:21 -0600 Subject: [PATCH 6/6] code refactor: addresing peer comments --- bundler/lib/bundler/settings/validator.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundler/lib/bundler/settings/validator.rb b/bundler/lib/bundler/settings/validator.rb index 7e1f3d240a17..093e9c2b62d9 100644 --- a/bundler/lib/bundler/settings/validator.rb +++ b/bundler/lib/bundler/settings/validator.rb @@ -77,9 +77,7 @@ def self.validate!(key, value, settings) 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? - fail!(key, value, "must be one of: #{valid_values.join(", ")}") - elsif !valid_values.include?(value.to_s) + if !value.nil? && !valid_values.include?(value.to_s) fail!(key, value, "must be one of: #{valid_values.join(", ")}") end end