diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-14 06:01:35 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-14 06:01:35 +0000 |
commit | 68ddd4d300e9a88737c4f37af74e1a0312949b2f (patch) | |
tree | 787e1e83d76934ce039eb336995a8d5bb53a89e6 /lib/bundler/cli.rb | |
parent | d636809c057432e8d42abe30c6c6785eb0721d77 (diff) |
Merge Bundler 2.1.0.pre.1 as developed version from upstream.
https://github.com/bundler/bundler/commit/a53709556b95a914e874b22ed2116a46b0528852
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/bundler/cli.rb')
-rw-r--r-- | lib/bundler/cli.rb | 174 |
1 files changed, 97 insertions, 77 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 3efe193613..4e3735847e 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -16,7 +16,7 @@ module Bundler def self.start(*) super - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException Bundler.ui = UI::Shell.new raise e ensure @@ -61,11 +61,6 @@ module Bundler 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 @@ -142,7 +137,7 @@ module Bundler 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 - deprecated_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile" + method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile" def init require "bundler/cli/init" Init.new(options.dup).run @@ -188,13 +183,13 @@ module Bundler If the bundle has already been installed, bundler will tell you so and then exit. D - deprecated_option "binstubs", :type => :string, :lazy_default => "bin", :banner => + method_option "binstubs", :type => :string, :lazy_default => "bin", :banner => "Generate bin stubs for bundled gems to ./bin" - deprecated_option "clean", :type => :boolean, :banner => + method_option "clean", :type => :boolean, :banner => "Run bundle clean automatically after install" - deprecated_option "deployment", :type => :boolean, :banner => + method_option "deployment", :type => :boolean, :banner => "Install using defaults tuned for deployment environments" - deprecated_option "frozen", :type => :boolean, :banner => + method_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" @@ -204,32 +199,37 @@ module Bundler "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" - deprecated_option "no-cache", :type => :boolean, :banner => + method_option "no-cache", :type => :boolean, :banner => "Don't update the existing gem cache." method_option "redownload", :type => :boolean, :aliases => "--force", :banner => "Force downloading every gem." - deprecated_option "no-prune", :type => :boolean, :banner => + method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." - deprecated_option "path", :type => :string, :banner => + 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" method_option "quiet", :type => :boolean, :banner => "Only output warnings and errors." - deprecated_option "shebang", :type => :string, :banner => + method_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" - deprecated_option "system", :type => :boolean, :banner => + method_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("|") - deprecated_option "without", :type => :array, :banner => + method_option "without", :type => :array, :banner => "Exclude gems that are part of the specified named group." - deprecated_option "with", :type => :array, :banner => + method_option "with", :type => :array, :banner => "Include gems that are part of the specified named group." map "i" => "install" def install - SharedHelpers.major_deprecation(3, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") + SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") + + %w[clean deployment frozen no-cache no-prune path shebang system without with].each do |option| + remembered_flag_deprecation(option) + end + require "bundler/cli/install" Bundler.settings.temporary(:no_install => false) do Install.new(options.dup).run @@ -275,57 +275,60 @@ module Bundler method_option "all", :type => :boolean, :banner => "Update everything." def update(*gems) - SharedHelpers.major_deprecation(3, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") + SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") require "bundler/cli/update" - Update.new(options, gems).run + Bundler.settings.temporary(:no_install => false) do + Update.new(options, gems).run + end end - desc "show GEM [OPTIONS]", "Shows all gems that are part of the bundle, or the path to a given gem" - long_desc <<-D - Show lists the names and versions of all gems that are required by your Gemfile. - Calling show with [GEM] will list the exact location of that gem on your machine. - D - method_option "paths", :type => :boolean, - :banner => "List the paths of all gems that are required by your Gemfile." - method_option "outdated", :type => :boolean, - :banner => "Show verbose output including whether gems are outdated." - def show(gem_name = nil) - if ARGV[0] == "show" - rest = ARGV[1..-1] - - new_command = rest.find {|arg| !arg.start_with?("--") } ? "info" : "list" - - new_arguments = rest.map do |arg| - next arg if arg != "--paths" - next "--path" if new_command == "info" + unless Bundler.feature_flag.bundler_3_mode? + desc "show GEM [OPTIONS]", "Shows all gems that are part of the bundle, or the path to a given gem" + long_desc <<-D + Show lists the names and versions of all gems that are required by your Gemfile. + Calling show with [GEM] will list the exact location of that gem on your machine. + D + method_option "paths", :type => :boolean, + :banner => "List the paths of all gems that are required by your Gemfile." + method_option "outdated", :type => :boolean, + :banner => "Show verbose output including whether gems are outdated." + def show(gem_name = nil) + if ARGV[0] == "show" + rest = ARGV[1..-1] + + if flag = rest.find{|arg| ["--verbose", "--outdated"].include?(arg) } + Bundler::SharedHelpers.major_deprecation(2, "the `#{flag}` flag to `bundle show` was undocumented and will be removed without replacement") + else + new_command = rest.find {|arg| !arg.start_with?("--") } ? "info" : "list" + + new_arguments = rest.map do |arg| + next arg if arg != "--paths" + next "--path" if new_command == "info" + end + + old_argv = ARGV.join(" ") + new_argv = [new_command, *new_arguments.compact].join(" ") + + Bundler::SharedHelpers.major_deprecation(2, "use `bundle #{new_argv}` instead of `bundle #{old_argv}`") + end end - - old_argv = ARGV.join(" ") - new_argv = [new_command, *new_arguments.compact].join(" ") - - Bundler::SharedHelpers.major_deprecation(3, "use `bundle #{new_argv}` instead of `bundle #{old_argv}`") - end - require "bundler/cli/show" - Show.new(options, gem_name).run - end - # TODO: 2.0 remove `bundle show` - - if Bundler.feature_flag.list_command? - desc "list", "List all gems in the bundle" - method_option "name-only", :type => :boolean, :banner => "print only the gem names" - method_option "only-group", :type => :string, :banner => "print gems from a particular group" - method_option "without-group", :type => :string, :banner => "print all gems expect from a group" - method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle" - def list - require "bundler/cli/list" - List.new(options).run + require "bundler/cli/show" + Show.new(options, gem_name).run end + end - map %w[ls] => "list" - else - map %w[list] => "show" + desc "list", "List all gems in the bundle" + method_option "name-only", :type => :boolean, :banner => "print only the gem names" + method_option "only-group", :type => :string, :banner => "print gems from a particular group" + method_option "without-group", :type => :string, :banner => "print all gems except from a group" + method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle" + def list + require "bundler/cli/list" + List.new(options).run end + map %w[ls] => "list" + desc "info GEM [OPTIONS]", "Show information for the given gem" method_option "path", :type => :boolean, :banner => "Print full path to gem" def info(gem_name) @@ -386,9 +389,10 @@ module Bundler "Do not attempt to fetch gems remotely and use the gem cache instead" method_option "pre", :type => :boolean, :banner => "Check for newer pre-release gems" method_option "source", :type => :array, :banner => "Check against a specific source" - method_option "strict", :type => :boolean, :banner => + strict_is_update = Bundler.feature_flag.forget_cli_options? + method_option "filter-strict", :type => :boolean, :aliases => strict_is_update ? [] : %w[--strict], :banner => "Only list newer versions allowed by your Gemfile requirements" - method_option "update-strict", :type => :boolean, :banner => + method_option "update-strict", :type => :boolean, :aliases => strict_is_update ? %w[--strict] : [], :banner => "Strict conservative resolution, do not allow any gem to be updated past latest --patch | --minor | --major" method_option "minor", :type => :boolean, :banner => "Prefer updating only to next minor version" method_option "major", :type => :boolean, :banner => "Prefer updating to next major version (default)" @@ -475,11 +479,8 @@ module Bundler will show the current value, as well as any superceded values and where they were specified. D - method_option "parseable", :type => :boolean, :banner => "Use minimal formatting for more parseable output" - def config(*args) - require "bundler/cli/config" - Config.new(options, args, self).run - end + require "bundler/cli/config" + subcommand "config", Config desc "open GEM", "Opens the source directory of the given bundled gem" def open(name) @@ -487,7 +488,7 @@ module Bundler Open.new(options, name).run end - if Bundler.feature_flag.console_command? + unless Bundler.feature_flag.bundler_3_mode? desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded" def console(group = nil) require "bundler/cli/console" @@ -524,7 +525,7 @@ module Bundler end end - if Bundler.feature_flag.viz_command? + unless Bundler.feature_flag.bundler_3_mode? desc "viz [OPTIONS]", "Generates a visual dependency graph", :hide => true long_desc <<-D Viz generates a PNG file of the current Gemfile as a dependency graph. @@ -537,7 +538,7 @@ module Bundler method_option :version, :type => :boolean, :default => false, :aliases => "-v", :desc => "Set to show each gem version." method_option :without, :type => :array, :default => [], :aliases => "-W", :banner => "GROUP[ GROUP...]", :desc => "Exclude gems that are part of the specified named group." def viz - SharedHelpers.major_deprecation 3, "The `viz` command has been moved to the `bundle-viz` gem, see https://github.com/bundler/bundler-viz" + SharedHelpers.major_deprecation 2, "The `viz` command has been moved to the `bundle-viz` gem, see https://github.com/bundler/bundler-viz" require "bundler/cli/viz" Viz.new(options.dup).run end @@ -547,14 +548,14 @@ module Bundler desc "gem NAME [OPTIONS]", "Creates a skeleton for creating a rubygem" method_option :exe, :type => :boolean, :default => false, :aliases => ["--bin", "-b"], :desc => "Generate a binary executable for your library." - method_option :coc, :type => :boolean, :desc => "Generate a code of conduct file. Set a default with `bundle config gem.coc true`." + method_option :coc, :type => :boolean, :desc => "Generate a code of conduct file. Set a default with `bundle config set gem.coc true`." method_option :edit, :type => :string, :aliases => "-e", :required => false, :banner => "EDITOR", :lazy_default => [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }, :desc => "Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)" method_option :ext, :type => :boolean, :default => false, :desc => "Generate the boilerplate for C extension code" - method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config gem.mit true`." + method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`." method_option :test, :type => :string, :lazy_default => "rspec", :aliases => "-t", :banner => "rspec", - :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config gem.test rspec`." + :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config set gem.test rspec`." def gem(name) end @@ -608,7 +609,7 @@ module Bundler method_option "group", :type => :string, :banner => "Install gem into a bundler group" def inject(name, version) - SharedHelpers.major_deprecation 3, "The `inject` command has been replaced by the `add` command" + SharedHelpers.major_deprecation 2, "The `inject` command has been replaced by the `add` command" require "bundler/cli/inject" Inject.new(options.dup, name, version).run end @@ -620,6 +621,8 @@ module Bundler "do not attempt to fetch remote gemspecs and use the local gem cache only" method_option "print", :type => :boolean, :default => false, :banner => "print the lockfile to STDOUT instead of writing to the file system" + method_option "gemfile", :type => :string, :banner => + "Use the specified gemfile instead of Gemfile" method_option "lockfile", :type => :string, :default => nil, :banner => "the path the lockfile should be written to" method_option "full-index", :type => :boolean, :default => false, :banner => @@ -714,7 +717,7 @@ module Bundler # Automatically invoke `bundle install` and resume if # Bundler.settings[:auto_install] exists. This is set through config cmd - # `bundle config auto_install 1`. + # `bundle config set auto_install 1`. # # Note that this method `nil`s out the global Definition object, so it # should be called first, before you instantiate anything like an @@ -786,5 +789,22 @@ module Bundler rescue RuntimeError nil end + + def remembered_flag_deprecation(name) + option = current_command.options[name] + flag_name = option.switch_name + + name_index = ARGV.find {|arg| flag_name == arg } + return unless name_index + + value = options[name] + value = value.join(" ").to_s if option.type == :array + + Bundler::SharedHelpers.major_deprecation 2,\ + "The `#{flag_name}` flag is deprecated because it relies on being " \ + "remembered accross bundler invokations, which bundler will no longer " \ + "do in future versions. Instead please use `bundle config #{name} " \ + "'#{value}'`, and stop using this flag" + end end end |