mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00

If the original `BUNDLE_GEMFILE` is different from the default, then the
suggestion wouldn't work as is.
Before:
```
$ util/rubocop
Could not find rubocop-1.30.1 in locally installed gems
Run `bundle install` to install missing gems.
$ rubygems git:(better-cmd-suggestion) ✗ bundle install
Could not locate Gemfile
```
After:
```
$ util/rubocop
Could not find rubocop-1.30.1 in locally installed gems
Run `bundle install --gemfile /path/to/rubygems/bundler/tool/bundler/lint_gems.rb` to install missing gems.
$ bundle install --gemfile /path/to/rubygems/bundler/tool/bundler/lint_gems.rb
Fetching gem metadata from https://rubygems.org/.........
Using ast 2.4.2
Using bundler 2.4.7
Using parser 3.1.2.0
Using rainbow 3.1.1
Using parallel 1.22.1
Using regexp_parser 2.5.0
Using rubocop-ast 1.18.0
Using rexml 3.2.5
Using ruby-progressbar 1.11.0
Using unicode-display_width 2.1.0
Fetching rubocop 1.30.1
Installing rubocop 1.30.1
Using rubocop-performance 1.14.2
Bundle complete! 2 Gemfile dependencies, 12 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ util/rubocop
Inspecting 345 files
.........................................................................................................................................................................................................................................................................................................................................................
345 files inspected, no offenses detected
```
bf1320d805
30 lines
963 B
Ruby
30 lines
963 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "shared_helpers"
|
|
|
|
if Bundler::SharedHelpers.in_bundle?
|
|
require_relative "../bundler"
|
|
|
|
if STDOUT.tty? || ENV["BUNDLER_FORCE_TTY"]
|
|
begin
|
|
Bundler.ui.silence { Bundler.setup }
|
|
rescue Bundler::BundlerError => e
|
|
Bundler.ui.error e.message
|
|
Bundler.ui.warn e.backtrace.join("\n") if ENV["DEBUG"]
|
|
if e.is_a?(Bundler::GemNotFound)
|
|
suggested_cmd = "bundle install"
|
|
original_gemfile = Bundler.original_env["BUNDLE_GEMFILE"]
|
|
suggested_cmd += " --gemfile #{original_gemfile}" if original_gemfile
|
|
Bundler.ui.warn "Run `#{suggested_cmd}` to install missing gems."
|
|
end
|
|
exit e.status_code
|
|
end
|
|
else
|
|
Bundler.ui.silence { Bundler.setup }
|
|
end
|
|
|
|
# We might be in the middle of shelling out to rubygems
|
|
# (RUBYOPT=-rbundler/setup), so we need to give rubygems the opportunity of
|
|
# not being silent.
|
|
Gem::DefaultUserInteraction.ui = nil
|
|
end
|