| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
module Bundler |
| 4 |
class CLI::Cache |
| 5 |
attr_reader :options |
| 6 |
|
| 7 |
def initialize(options) |
| 8 |
@options = options |
| 9 |
end |
| 10 |
|
| 11 |
def run |
| 12 |
Bundler.ui.level = "warn" if options[:quiet] |
| 13 |
Bundler.settings.set_command_option_if_given :path, options[:path] |
| 14 |
Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"] |
| 15 |
|
| 16 |
setup_cache_all |
| 17 |
install |
| 18 |
|
| 19 |
# TODO: move cache contents here now that all bundles are locked |
| 20 |
custom_path = Bundler.settings[:path] if options[:path] |
| 21 |
|
| 22 |
Bundler.settings.temporary(cache_all_platforms: options["all-platforms"]) do |
| 23 |
Bundler.load.cache(custom_path) |
| 24 |
end |
| 25 |
end |
| 26 |
|
| 27 |
private |
| 28 |
|
| 29 |
def install |
| 30 |
require_relative "install" |
| 31 |
options = self.options.dup |
| 32 |
options["local"] = false if Bundler.settings[:cache_all_platforms] |
| 33 |
options["no-cache"] = true |
| 34 |
Bundler::CLI::Install.new(options).run |
| 35 |
end |
| 36 |
|
| 37 |
def setup_cache_all |
| 38 |
all = options.fetch(:all, Bundler.feature_flag.cache_all? || nil) |
| 39 |
|
| 40 |
Bundler.settings.set_command_option_if_given :cache_all, all |
| 41 |
end |
| 42 |
end |
| 43 |
end |