Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

[2.0] Stop remembering CLI options in Bundler 2 #5811

Merged
merged 18 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ module Bundler
autoload :VersionRanges, "bundler/version_ranges"

class << self
attr_writer :bundle_path

def configure
@configured ||= configure_gem_home_and_path
end
Expand Down Expand Up @@ -233,7 +231,7 @@ def app_config_path

def app_cache(custom_path = nil)
path = custom_path || root
path.join(settings.app_cache_path)
Pathname.new(path).join(settings.app_cache_path)
end

def tmp(name = Process.pid.to_s)
Expand Down
37 changes: 21 additions & 16 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ def initialize(*args)
Bundler.reset_paths!
end

Bundler.settings[:retry] = options[:retry] if options[:retry]
Bundler.settings.set_command_option_if_given :retry, options[:retry]

current_cmd = args.last[:current_command].name
auto_install if AUTO_INSTALL_CMDS.include?(current_cmd)
rescue UnknownArgumentError => e
raise InvalidOption, e.message
ensure
self.options ||= {}
Bundler.settings.cli_flags_given = !options.empty?
unprinted_warnings = Bundler.ui.unprinted_warnings
Bundler.ui = UI::Shell.new(options)
Bundler.ui.level = "debug" if options["verbose"]
Expand All @@ -53,6 +52,11 @@ def initialize(*args)
end
end

def self.deprecated_option(*args, &blk)
return if Bundler.feature_flag.forget_cli_options?
method_option(*args, &blk)
end

check_unknown_options!(:except => [:config, :exec])
stop_on_unknown_option! :exec

Expand Down Expand Up @@ -113,7 +117,7 @@ def self.handle_no_command_error(command, has_namespace = $thor_runner)
Gemfile to a gem with a gemspec, the --gemspec option will automatically add each
dependency listed in the gemspec file to the newly created Gemfile.
D
method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile"
deprecated_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile"
def init
require "bundler/cli/init"
Init.new(options.dup).run
Expand All @@ -130,7 +134,7 @@ def init
method_option "gemfile", :type => :string, :banner =>
"Use the specified gemfile instead of Gemfile"
method_option "path", :type => :string, :banner =>
"Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine"
"Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME).#{" Bundler will remember this value for future installs on this machine" unless Bundler.feature_flag.forget_cli_options?}"
map "c" => "check"
def check
require "bundler/cli/check"
Expand All @@ -148,13 +152,13 @@ def check

If the bundle has already been installed, bundler will tell you so and then exit.
D
method_option "binstubs", :type => :string, :lazy_default => "bin", :banner =>
deprecated_option "binstubs", :type => :string, :lazy_default => "bin", :banner =>
"Generate bin stubs for bundled gems to ./bin"
method_option "clean", :type => :boolean, :banner =>
deprecated_option "clean", :type => :boolean, :banner =>
"Run bundle clean automatically after install"
method_option "deployment", :type => :boolean, :banner =>
deprecated_option "deployment", :type => :boolean, :banner =>
"Install using defaults tuned for deployment environments"
method_option "frozen", :type => :boolean, :banner =>
deprecated_option "frozen", :type => :boolean, :banner =>
"Do not allow the Gemfile.lock to be updated after this install"
method_option "full-index", :type => :boolean, :banner =>
"Fall back to using the single-file index of all gems"
Expand All @@ -164,28 +168,29 @@ def check
"Specify the number of jobs to run in parallel"
method_option "local", :type => :boolean, :banner =>
"Do not attempt to fetch gems remotely and use the gem cache instead"
method_option "no-cache", :type => :boolean, :banner =>
deprecated_option "no-cache", :type => :boolean, :banner =>
"Don't update the existing gem cache."
method_option "force", :type => :boolean, :banner =>
method_option "redownload", :type => :boolean, :aliases =>
[Bundler.feature_flag.forget_cli_options? ? nil : "--force"].compact, :banner =>
"Force downloading every gem."
method_option "no-prune", :type => :boolean, :banner =>
deprecated_option "no-prune", :type => :boolean, :banner =>
"Don't remove stale gems from the cache."
method_option "path", :type => :string, :banner =>
deprecated_option "path", :type => :string, :banner =>
"Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine"
method_option "quiet", :type => :boolean, :banner =>
"Only output warnings and errors."
method_option "shebang", :type => :string, :banner =>
deprecated_option "shebang", :type => :string, :banner =>
"Specify a different shebang executable name than the default (usually 'ruby')"
method_option "standalone", :type => :array, :lazy_default => [], :banner =>
"Make a bundle that can work without the Bundler runtime"
method_option "system", :type => :boolean, :banner =>
deprecated_option "system", :type => :boolean, :banner =>
"Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application"
method_option "trust-policy", :alias => "P", :type => :string, :banner =>
"Gem trust policy (like gem install -P). Must be one of " +
Bundler.rubygems.security_policy_keys.join("|")
method_option "without", :type => :array, :banner =>
deprecated_option "without", :type => :array, :banner =>
"Exclude gems that are part of the specified named group."
method_option "with", :type => :array, :banner =>
deprecated_option "with", :type => :array, :banner =>
"Include gems that are part of the specified named group."
map "i" => "install"
def install
Expand Down
7 changes: 4 additions & 3 deletions lib/bundler/cli/binstubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ def initialize(options, gems)

def run
Bundler.definition.validate_runtime!
Bundler.settings[:bin] = options["path"] if options["path"]
Bundler.settings[:bin] = nil if options["path"] && options["path"].empty?
Bundler.settings[:shebang] = options["shebang"] if options["shebang"]
path_option = options["path"]
path_option = nil if path_option && path_option.empty?
Bundler.settings.set_command_option :bin, path_option if options["path"]
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]
installer = Installer.new(Bundler.root, Bundler.definition)

if gems.empty?
Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/cli/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def run
Bundler.definition.validate_runtime!
Bundler.definition.resolve_with_cache!
setup_cache_all
Bundler.settings[:cache_all_platforms] = options["all-platforms"] if options.key?("all-platforms")
Bundler.settings.set_command_option_if_given :cache_all_platforms, options["all-platforms"]
Bundler.load.cache
Bundler.settings[:no_prune] = true if options["no-prune"]
Bundler.settings.set_command_option_if_given :no_prune, options["no-prune"]
Bundler.load.lock
rescue GemNotFound => e
Bundler.ui.error(e.message)
Expand All @@ -24,7 +24,7 @@ def run
private

def setup_cache_all
Bundler.settings[:cache_all] = options[:all] if options.key?("all")
Bundler.settings.set_command_option_if_given :cache_all, options[:all]

if Bundler.definition.has_local_dependencies? && !Bundler.settings[:cache_all]
Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \
Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/cli/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def initialize(options)
end

def run
if options[:path]
Bundler.settings[:path] = File.expand_path(options[:path])
Bundler.settings[:disable_shared_gems] = true
if path = options[:path]
Bundler.settings.set_command_option :path, path
Bundler.settings.set_command_option :disable_shared_gems, true
end

begin
Expand Down
3 changes: 1 addition & 2 deletions lib/bundler/cli/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def run

def require_path_or_force
if !Bundler.settings[:path] && !options[:force]
Bundler.ui.error "Cleaning all the gems on your system is dangerous! " \
raise InvalidOption, "Cleaning all the gems on your system is dangerous! " \
"If you're sure you want to remove every system gem not in this " \
"bundle, run `bundle clean --force`."
exit 1
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/cli/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def self.print_post_install_message(name, msg)
end

def self.output_without_groups_message
return unless Bundler.settings.without.any?
return if Bundler.settings[:without].empty?
Bundler.ui.confirm without_groups_message
end

def self.without_groups_message
groups = Bundler.settings.without
groups = Bundler.settings[:without]
group_list = [groups[0...-1].join(", "), groups[-1..-1]].
reject {|s| s.to_s.empty? }.join(" and ")
group_str = (groups.size == 1) ? "group" : "groups"
Expand Down
94 changes: 43 additions & 51 deletions lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ def run

warn_if_root

[:with, :without].each do |option|
if options[option]
options[option] = options[option].join(":").tr(" ", ":").split(":")
end
end

check_for_group_conflicts

normalize_groups

Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Bundler::FREEBSD
Expand All @@ -46,15 +38,15 @@ def run
options[:local] = true if Bundler.app_cache.exist?

if Bundler.feature_flag.deployment_means_frozen?
Bundler.settings.temporary(:deployment => true)
Bundler.settings.set_command_option :deployment, true
else
Bundler.settings[:frozen] ||= true
Bundler.settings.set_command_option :frozen, true
end
end

# When install is called with --no-deployment, disable deployment mode
if options[:deployment] == false
Bundler.settings.delete(:frozen)
Bundler.settings.set_command_option :frozen, nil
options[:system] = true
end

Expand All @@ -78,8 +70,8 @@ def run
Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}."
Bundler::CLI::Common.output_without_groups_message

if Bundler.settings[:path]
absolute_path = File.expand_path(Bundler.settings[:path])
if path = Bundler.settings[:path]
absolute_path = File.expand_path(path)
relative_path = absolute_path.sub(File.expand_path(".") + File::SEPARATOR, "." + File::SEPARATOR)
Bundler.ui.confirm "Bundled gems are installed into #{relative_path}."
else
Expand Down Expand Up @@ -131,15 +123,11 @@ def gems_installed_for(definition)
"#{count} #{count == 1 ? "gem" : "gems"} now installed"
end

def check_for_group_conflicts
if options[:without] && options[:with]
conflicting_groups = options[:without] & options[:with]
unless conflicting_groups.empty?
Bundler.ui.error "You can't list a group in both, --with and --without." \
" The offending groups are: #{conflicting_groups.join(", ")}."
exit 1
end
end
def check_for_group_conflicts_in_cli_options
conflicting_groups = Array(options[:without]) & Array(options[:with])
return if conflicting_groups.empty?
raise InvalidOption, "You can't list a group in both with and without." \
" The offending groups are: #{conflicting_groups.join(", ")}."
end

def check_for_options_conflicts
Expand All @@ -152,58 +140,62 @@ def check_for_options_conflicts
end

def check_trust_policy
if options["trust-policy"]
unless Bundler.rubygems.security_policies.keys.include?(options["trust-policy"])
Bundler.ui.error "RubyGems doesn't know about trust policy '#{options["trust-policy"]}'. " \
"The known policies are: #{Bundler.rubygems.security_policies.keys.join(", ")}."
exit 1
end
Bundler.settings["trust-policy"] = options["trust-policy"]
else
Bundler.settings["trust-policy"] = nil if Bundler.settings["trust-policy"]
trust_policy = options["trust-policy"]
unless Bundler.rubygems.security_policies.keys.unshift(nil).include?(trust_policy)
raise InvalidOption, "RubyGems doesn't know about trust policy '#{trust_policy}'. " \
"The known policies are: #{Bundler.rubygems.security_policies.keys.join(", ")}."
end
Bundler.settings.set_command_option_if_given :"trust-policy", trust_policy
end

def normalize_groups
Bundler.settings.with = [] if options[:with] && options[:with].empty?
Bundler.settings.without = [] if options[:without] && options[:without].empty?
options[:with] &&= options[:with].join(":").tr(" ", ":").split(":")
options[:without] &&= options[:without].join(":").tr(" ", ":").split(":")

check_for_group_conflicts_in_cli_options

with = options.fetch("with", [])
with |= Bundler.settings.with.map(&:to_s)
Bundler.settings.set_command_option_if_given :with, options[:with]
Bundler.settings.set_command_option_if_given :without, options[:without]

with = options.fetch(:with, [])
with |= Bundler.settings[:with].map(&:to_s)
with -= options[:without] if options[:without]

without = options.fetch("without", [])
without |= Bundler.settings.without.map(&:to_s)
without = options.fetch(:without, [])
without |= Bundler.settings[:without].map(&:to_s)
without -= options[:with] if options[:with]

options[:with] = with
options[:without] = without
end

def normalize_settings
Bundler.settings[:path] = nil if options[:system]
Bundler.settings[:path] = "vendor/bundle" if options[:deployment]
Bundler.settings[:path] = options["path"] if options["path"]
Bundler.settings[:path] ||= "bundle" if options["standalone"]
Bundler.settings.set_command_option :path, nil if options[:system]
Bundler.settings.set_command_option :path, "vendor/bundle" if options[:deployment]
Bundler.settings.set_command_option_if_given :path, options["path"]
Bundler.settings.set_command_option :path, "bundle" if options["standalone"] && Bundler.settings[:path].nil?

Bundler.settings[:bin] = options["binstubs"] if options["binstubs"]
Bundler.settings[:bin] = nil if options["binstubs"] && options["binstubs"].empty?
bin_option = options["binstubs"]
bin_option = nil if bin_option && bin_option.empty?
Bundler.settings.set_command_option :bin, bin_option if options["binstubs"]

Bundler.settings[:shebang] = options["shebang"] if options["shebang"]
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]

Bundler.settings[:jobs] = options["jobs"] if options["jobs"]
Bundler.settings.set_command_option_if_given :jobs, options["jobs"]

Bundler.settings[:no_prune] = true if options["no-prune"]
Bundler.settings.set_command_option_if_given :no_prune, options["no-prune"]

Bundler.settings[:no_install] = true if options["no-install"]
Bundler.settings.set_command_option_if_given :no_install, options["no-install"]

Bundler.settings[:clean] = options["clean"] if options["clean"]
Bundler.settings.set_command_option_if_given :clean, options["clean"]

Bundler.settings.without = options[:without] unless Bundler.settings.without == options[:without]
Bundler.settings.with = options[:with] unless Bundler.settings.with == options[:with]
Bundler.settings.set_command_option :without, options[:without] unless Bundler.settings[:without] == options[:without]
Bundler.settings.set_command_option :with, options[:with] unless Bundler.settings[:with] == options[:with]

disable_shared_gems = Bundler.settings[:path] ? true : nil
Bundler.settings[:disable_shared_gems] = disable_shared_gems unless Bundler.settings[:disable_shared_gems] == disable_shared_gems
Bundler.settings.set_command_option :disable_shared_gems, disable_shared_gems unless Bundler.settings[:disable_shared_gems] == disable_shared_gems

options[:force] = options[:redownload]
end

def warn_ambiguous_gems
Expand Down
10 changes: 5 additions & 5 deletions lib/bundler/cli/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def initialize(options)

def run
Bundler.ui.level = "error" if options[:quiet]
Bundler.settings[:path] = File.expand_path(options[:path]) if options[:path]
Bundler.settings[:cache_all_platforms] = options["all-platforms"] if options.key?("all-platforms")
Bundler.settings[:cache_path] = options["cache-path"] if options.key?("cache-path")
Bundler.settings.set_command_option_if_given :path, options[:path]
Bundler.settings.set_command_option_if_given :cache_all_platforms, options["all-platforms"]
Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"]

setup_cache_all
install

# TODO: move cache contents here now that all bundles are locked
custom_path = Pathname.new(options[:path]) if options[:path]
custom_path = Bundler.settings[:path] if options[:path]
Bundler.load.cache(custom_path)
end

Expand All @@ -35,7 +35,7 @@ def install
end

def setup_cache_all
Bundler.settings[:cache_all] = options[:all] if options.key?("all")
Bundler.settings.set_command_option_if_given :cache_all, options[:all]

if Bundler.definition.has_local_dependencies? && !Bundler.settings[:cache_all]
Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def run
opts["update"] = true
opts["local"] = options[:local]

Bundler.settings[:jobs] = opts["jobs"] if opts["jobs"]
Bundler.settings.set_command_option_if_given :jobs, opts["jobs"]

Bundler.definition.validate_runtime!
installer = Installer.install Bundler.root, Bundler.definition, opts
Expand Down