Skip to content

Conversation

@jonbarlo
Copy link
Contributor

@jonbarlo jonbarlo commented Jul 29, 2025

What was the end-user or developer problem that led to this PR?

Closes#8786

The default_cli_command feature allows users to configure what command Bundler runs when no specific command is provided.

What is your fix for the problem, implemented in this PR?

Implementation Details

  1. bundler/lib/bundler/settings/validator.rb

    • Added validation rule for default_cli_command
    • Ensures only valid values (install or cli_help) are accepted
    • Provides clear error messages for invalid values
  2. bundler/lib/bundler/settings.rb

    • Added default_cli_command to STRING_KEYS list
  3. bundler/lib/bundler/cli.rb

    • Updated version method to not show default timestamp (1980-01-02)
    • Updated cli_help method to use enhanced man-based help system
  4. bundler/spec/bundler/settings_spec.rb

    • Tests for valid values, invalid values, and nil values

Key Technical Changes

Validation Rule

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

Version Display Fix

# 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

Enhanced Help System

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)
end

Setting the Default Command

Users can configure the default CLI command using Bundler's settings system:

# Set to run 'install' by default (Bundler 3 behavior)
bundle config set default_cli_command install

# Set to run 'cli_help' by default (Bundler 4 behavior)
bundle config set default_cli_command cli_help

Valid Values

The default_cli_command setting accepts only two valid values:

  • install - Runs bundle install when no command is specified (Bundler 3 behavior)
  • cli_help - Displays usage help when no command is specified (Bundler 4 behavior)

Make sure the following tasks are checked

@deivid-rodriguez deivid-rodriguez mentioned this pull request Aug 12, 2025
21 tasks
)
end

it "rejects nil values" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this test to match the implementation and name it it "accepts nil values".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the code in the rule checking for !value.nil? in order to not raise an error it's not even triggered by this test, because we Settings#set_local returns early if the previous value of the setting (nil in this case), matches the value passed to #set_local (nil, too).

So I'd add an extra test it "accepts nil values for unsetting an existing value of the setting" that first sets settings.set_local("default_cli_command", "install") and then checks that settings.set_local("default_cli_command", nil) does not raise an error.

@hsbt hsbt force-pushed the feature/default-cli-command branch from 44ea10b to 5913a7a Compare September 24, 2025 11:34
@hsbt hsbt force-pushed the feature/default-cli-command branch from 5913a7a to e042f4a Compare October 23, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants