| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
module Bundler |
| 4 |
class CLI::Binstubs |
| 5 |
attr_reader :options, :gems |
| 6 |
def initialize(options, gems) |
| 7 |
@options = options |
| 8 |
@gems = gems |
| 9 |
end |
| 10 |
|
| 11 |
def run |
| 12 |
Bundler.definition.validate_runtime! |
| 13 |
path_option = options["path"] |
| 14 |
path_option = nil if path_option&.empty? |
| 15 |
Bundler.settings.set_command_option :bin, path_option if options["path"] |
| 16 |
Bundler.settings.set_command_option_if_given :shebang, options["shebang"] |
| 17 |
installer = Installer.new(Bundler.root, Bundler.definition) |
| 18 |
|
| 19 |
installer_opts = { |
| 20 |
force: options[:force], |
| 21 |
binstubs_cmd: true, |
| 22 |
all_platforms: options["all-platforms"], |
| 23 |
} |
| 24 |
|
| 25 |
if options[:all] |
| 26 |
raise InvalidOption, "Cannot specify --all with specific gems" unless gems.empty? |
| 27 |
@gems = Bundler.definition.specs.map(&:name) |
| 28 |
installer_opts.delete(:binstubs_cmd) |
| 29 |
elsif gems.empty? |
| 30 |
Bundler.ui.error "`bundle binstubs` needs at least one gem to run." |
| 31 |
exit 1 |
| 32 |
end |
| 33 |
|
| 34 |
gems.each do |gem_name| |
| 35 |
spec = Bundler.definition.specs.find {|s| s.name == gem_name } |
| 36 |
unless spec |
| 37 |
raise GemNotFound, Bundler::CLI::Common.gem_not_found_message( |
| 38 |
gem_name, Bundler.definition.specs |
| 39 |
) |
| 40 |
end |
| 41 |
|
| 42 |
if options[:standalone] |
| 43 |
if gem_name == "bundler" |
| 44 |
Bundler.ui.warn("Sorry, Bundler can only be run via RubyGems.") unless options[:all] |
| 45 |
next |
| 46 |
end |
| 47 |
|
| 48 |
Bundler.settings.temporary(path: Bundler.settings[:path] || Bundler.root) do |
| 49 |
installer.generate_standalone_bundler_executable_stubs(spec, installer_opts) |
| 50 |
end |
| 51 |
else |
| 52 |
installer.generate_bundler_executable_stubs(spec, installer_opts) |
| 53 |
end |
| 54 |
end |
| 55 |
end |
| 56 |
end |
| 57 |
end |