Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,28 @@ def cli_help
self.class.send(:class_options_help, shell)
end

desc "install_or_cli_help", "Tries to run bundle install but prints a summary of bundler commands if there is no Gemfile", hide: true
def install_or_cli_help
invoke_other_command("install")
rescue GemfileNotFound => error
Bundler.ui.error error.message, wrap: true
invoke_other_command("cli_help")
end

def self.default_command(meth = nil)
return super if meth

default_cli_command = Bundler.settings[:default_cli_command]
return default_cli_command if default_cli_command

Bundler.ui.warn(<<~MSG)
In the next version of Bundler, running `bundle` without argument will no longer run `bundle install`.
Instead, the `help` command will be displayed.

If you'd like to keep the previous behaviour please run `bundle config set default_cli_command install --global`.
MSG
unless Bundler.settings[:default_cli_command]
Bundler.ui.info <<-MSG
In the feature version of Bundler, running `bundle` without argument will no longer run `bundle install`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In the feature version of Bundler, running `bundle` without argument will no longer run `bundle install`.
In a future version of Bundler, running `bundle` without argument will no longer run `bundle install`.

Instead, the `cli_help` command will be displayed. Please use `bundle install` explicitly for scripts like CI/CD.
If you wish to use feature behavior now with `bundle config set default_cli_command cli_help --global`
Copy link
Member

@eregon eregon Nov 29, 2025

Choose a reason for hiding this comment

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

Suggested change
If you wish to use feature behavior now with `bundle config set default_cli_command cli_help --global`
You can use the future behavior now with `bundle config set default_cli_command cli_help --global`,

or you can continue to use the old behavior with `bundle config set default_cli_command install_or_cli_help --global`.
This message will be removed after a default_cli_command value is set.
MSG
end

"install"
Bundler.settings[:default_cli_command] || "install_or_cli_help"
end

class_option "no-color", type: :boolean, desc: "Disable colorization in output"
Expand Down Expand Up @@ -723,6 +731,19 @@ def current_command
config[:current_command]
end

def invoke_other_command(name)
_, _, config = @_initializer
original_command = config[:current_command]
command = self.class.all_commands[name]
config[:current_command] = command
send(name)
ensure
config[:current_command] = original_command
end

def current_command=(command)
end

def print_command
return unless Bundler.ui.debug?
cmd = current_command
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/vendor/thor/lib/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def normalize_command_name(meth) #:nodoc:
# alias name.
def find_command_possibilities(meth)
len = meth.to_s.length
possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort
possibilities = all_commands.reject { |_k, c| c.hidden? }.merge(map).keys.select { |n| meth == n[0, len] }.sort
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq

if possibilities.include?(meth)
Expand Down
12 changes: 4 additions & 8 deletions bundler/spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,11 @@ def out_with_macos_man_workaround
end

context "with no arguments" do
it "installs and log a warning by default" do
it "tries to installs by default but print help on missing Gemfile" do
bundle "", raise_on_error: false
expect(err).to include("running `bundle` without argument will no longer run `bundle install`.")
expect(err).to include("Could not locate Gemfile")
end
expect(out).to include("In the feature version of Bundler")

it "prints a concise help message when default_cli_command set to cli_help" do
bundle "config set default_cli_command cli_help"
bundle ""
expect(err).to be_empty
expect(out).to include("Bundler version #{Bundler::VERSION}").
and include("\n\nBundler commands:\n\n").
and include("\n\n Primary commands:\n").
Expand All @@ -105,8 +100,9 @@ def out_with_macos_man_workaround
end

it "runs bundle install when default_cli_command set to install" do
bundle "config set default_cli_command install"
bundle "config set default_cli_command install_or_cli_help"
bundle "", raise_on_error: false
expect(out).to_not include("In the feature version of Bundler")
expect(err).to include("Could not locate Gemfile")
end
end
Expand Down
2 changes: 1 addition & 1 deletion bundler/spec/other/cli_dispatch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

it "print a friendly error when ambiguous" do
bundle "in", raise_on_error: false
expect(err).to eq("Ambiguous command in matches [info, init, inject, install]")
expect(err).to eq("Ambiguous command in matches [info, init, install]")
end
end
14 changes: 14 additions & 0 deletions tool/automatiek/thor-v1.4.0.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
diff --git a/bundler/lib/bundler/vendor/thor/lib/thor.rb b/bundler/lib/bundler/vendor/thor/lib/thor.rb
index bfd9f5c914..945bdbd551 100644
--- a/bundler/lib/bundler/vendor/thor/lib/thor.rb
+++ b/bundler/lib/bundler/vendor/thor/lib/thor.rb
@@ -625,7 +625,7 @@ def normalize_command_name(meth) #:nodoc:
# alias name.
def find_command_possibilities(meth)
len = meth.to_s.length
- possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort
+ possibilities = all_commands.reject { |_k, c| c.hidden? }.merge(map).keys.select { |n| meth == n[0, len] }.sort
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq

if possibilities.include?(meth)

diff --git a/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb b/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb
index 95f8b16e31..f0ce6df96c 100644
--- a/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb
Expand Down