| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
module Bundler |
| 4 |
class CLI::Lock |
| 5 |
attr_reader :options |
| 6 |
|
| 7 |
def initialize(options) |
| 8 |
@options = options |
| 9 |
end |
| 10 |
|
| 11 |
def run |
| 12 |
unless Bundler.default_gemfile |
| 13 |
Bundler.ui.error "Unable to find a Gemfile to lock" |
| 14 |
exit 1 |
| 15 |
end |
| 16 |
|
| 17 |
print = options[:print] |
| 18 |
previous_output_stream = Bundler.ui.output_stream |
| 19 |
Bundler.ui.output_stream = :stderr if print |
| 20 |
|
| 21 |
Bundler::Fetcher.disable_endpoint = options["full-index"] |
| 22 |
|
| 23 |
update = options[:update] |
| 24 |
conservative = options[:conservative] |
| 25 |
bundler = options[:bundler] |
| 26 |
|
| 27 |
if update.is_a?(Array) # unlocking specific gems |
| 28 |
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update) |
| 29 |
update = { gems: update, conservative: conservative } |
| 30 |
elsif update && conservative |
| 31 |
update = { conservative: conservative } |
| 32 |
elsif update && bundler |
| 33 |
update = { bundler: bundler } |
| 34 |
end |
| 35 |
|
| 36 |
file = options[:lockfile] |
| 37 |
file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile |
| 38 |
|
| 39 |
Bundler.settings.temporary(frozen: false) do |
| 40 |
definition = Bundler.definition(update, file) |
| 41 |
|
| 42 |
Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update] |
| 43 |
|
| 44 |
options["remove-platform"].each do |platform| |
| 45 |
definition.remove_platform(platform) |
| 46 |
end |
| 47 |
|
| 48 |
options["add-platform"].each do |platform_string| |
| 49 |
platform = Gem::Platform.new(platform_string) |
| 50 |
if platform.to_s == "unknown" |
| 51 |
Bundler.ui.error "The platform `#{platform_string}` is unknown to RubyGems and can't be added to the lockfile." |
| 52 |
exit 1 |
| 53 |
end |
| 54 |
definition.add_platform(platform) |
| 55 |
end |
| 56 |
|
| 57 |
if definition.platforms.empty? |
| 58 |
raise InvalidOption, "Removing all platforms from the bundle is not allowed" |
| 59 |
end |
| 60 |
|
| 61 |
definition.resolve_remotely! unless options[:local] |
| 62 |
|
| 63 |
if print |
| 64 |
puts definition.to_lock |
| 65 |
else |
| 66 |
puts "Writing lockfile to #{file}" |
| 67 |
definition.lock |
| 68 |
end |
| 69 |
end |
| 70 |
|
| 71 |
Bundler.ui.output_stream = previous_output_stream |
| 72 |
end |
| 73 |
end |
| 74 |
end |