summaryrefslogtreecommitdiff
path: root/lib/bundler/cli.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2019-11-11 17:57:45 +0900
committerSHIBATA Hiroshi <hsbt@ruby-lang.org>2019-11-11 18:56:25 +0900
commit7585bc31877d4f9725f8de51b4a2faf47acb6f34 (patch)
treeadf61a7c20f7e54b595ebde05284b5e2862f552c /lib/bundler/cli.rb
parentfd69f82675bf93a848e5aa58d117bf8bbf604188 (diff)
Merge Bundler 2.1.0.pre.3
Features: - Add caller information to some deprecation messages to make them easier to fix [#7361](https://github.com/bundler/bundler/pull/7361) - Reconcile `bundle cache` vs `bundle package` everywhere. Now in docs, CLI help and everywhere else `bundle cache` is the preferred version and `bundle package` remains as an alias [#7389](https://github.com/bundler/bundler/pull/7389) - Display some basic `bundler` documentation together with ruby's RDoc based documentation [#7394](https://github.com/bundler/bundler/pull/7394) Bugfixes: - Fix typos deprecation message and upgrading docs [#7374](https://github.com/bundler/bundler/pull/7374) - Deprecation warnings about `taint` usage on ruby 2.7 [#7385](https://github.com/bundler/bundler/pull/7385) - Fix `--help` flag not correctly delegating to `man` when used with command aliases [#7388](https://github.com/bundler/bundler/pull/7388) - `bundle add` should cache newly added gems if an application cache exists [#7393](https://github.com/bundler/bundler/pull/7393) - Stop using an insecure folder as a "fallback home" when user home is not defined [#7416](https://github.com/bundler/bundler/pull/7416) - Fix `bundler/inline` warning about `Bundler.root` redefinition [#7417](https://github.com/bundler/bundler/pull/7417)
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2668
Diffstat (limited to 'lib/bundler/cli.rb')
-rw-r--r--lib/bundler/cli.rb80
1 files changed, 55 insertions, 25 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 45db2a3200..d7f749a672 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -9,15 +9,19 @@ module Bundler
package_name "Bundler"
AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean].freeze
- PARSEABLE_COMMANDS = %w[
- check config help exec platform show version
- ].freeze
+ PARSEABLE_COMMANDS = %w[check config help exec platform show version].freeze
+
+ COMMAND_ALIASES = {
+ "check" => "c",
+ "install" => "i",
+ "list" => "ls",
+ "exec" => ["e", "ex", "exe"],
+ "cache" => ["package", "pack"],
+ "version" => ["-v", "--version"],
+ }.freeze
def self.start(*)
super
- rescue Exception => e # rubocop:disable Lint/RescueException
- Bundler.ui = UI::Shell.new
- raise e
ensure
Bundler::SharedHelpers.print_major_deprecations!
end
@@ -29,6 +33,24 @@ module Bundler
end
end
+ def self.all_aliases
+ @all_aliases ||= begin
+ command_aliases = {}
+
+ COMMAND_ALIASES.each do |name, aliases|
+ Array(aliases).each do |one_alias|
+ command_aliases[one_alias] = name
+ end
+ end
+
+ command_aliases
+ end
+ end
+
+ def self.aliases_for(command_name)
+ COMMAND_ALIASES.select {|k, _| k == command_name }.invert
+ end
+
def initialize(*args)
super
@@ -68,9 +90,7 @@ module Bundler
version
Bundler.ui.info "\n"
- primary_commands = ["install", "update",
- Bundler.feature_flag.bundler_3_mode? ? "cache" : "package",
- "exec", "config", "help"]
+ primary_commands = ["install", "update", "cache", "exec", "config", "help"]
list = self.class.printable_commands(true)
by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] }
@@ -154,7 +174,6 @@ module Bundler
"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" unless Bundler.feature_flag.forget_cli_options?}"
- map "c" => "check"
def check
remembered_flag_deprecation("path")
@@ -162,6 +181,8 @@ module Bundler
Check.new(options).run
end
+ map aliases_for("check")
+
desc "remove [GEM [GEM ...]]", "Removes gems from the Gemfile"
long_desc <<-D
Removes the given gems from the Gemfile while ensuring that the resulting Gemfile is still valid. If the gem is not found, Bundler prints a error message and if gem could not be removed due to any reason Bundler will display a warning.
@@ -223,7 +244,6 @@ module Bundler
"Exclude gems that are part of the specified named group."
method_option "with", :type => :array, :banner =>
"Include gems that are part of the specified named group."
- map "i" => "install"
def install
SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force")
@@ -237,6 +257,8 @@ module Bundler
end
end
+ map aliases_for("install")
+
desc "update [OPTIONS]", "Update the current environment"
long_desc <<-D
Update will install the newest versions of the gems listed in the Gemfile. Use
@@ -328,7 +350,7 @@ module Bundler
List.new(options).run
end
- map %w[ls] => "list"
+ map aliases_for("list")
desc "info GEM [OPTIONS]", "Show information for the given gem"
method_option "path", :type => :boolean, :banner => "Print full path to gem"
@@ -412,7 +434,7 @@ module Bundler
Outdated.new(options, gems).run
end
- desc "#{Bundler.feature_flag.bundler_3_mode? ? :cache : :package} [OPTIONS]", "Locks and then caches all of the gems into vendor/cache"
+ desc "cache [OPTIONS]", "Locks and then caches all of the gems into vendor/cache"
unless Bundler.feature_flag.cache_all?
method_option "all", :type => :boolean,
:banner => "Include all sources (including path and git)."
@@ -421,24 +443,25 @@ module Bundler
method_option "cache-path", :type => :string, :banner =>
"Specify a different cache path than the default (vendor/cache)."
method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile"
- method_option "no-install", :type => :boolean, :banner => "Don't install the gems, only the package."
+ method_option "no-install", :type => :boolean, :banner => "Don't install the gems, only update the cache."
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
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" unless Bundler.feature_flag.forget_cli_options?}"
method_option "quiet", :type => :boolean, :banner => "Only output warnings and errors."
method_option "frozen", :type => :boolean, :banner =>
- "Do not allow the Gemfile.lock to be updated after this package operation's install"
+ "Do not allow the Gemfile.lock to be updated after this bundle cache operation's install"
long_desc <<-D
- The package command will copy the .gem files for every gem in the bundle into the
+ The cache command will copy the .gem files for every gem in the bundle into the
directory ./vendor/cache. If you then check that directory into your source
control repository, others who check out your source will be able to install the
bundle without having to download any additional gems.
D
- def package
- require_relative "cli/package"
- Package.new(options).run
+ def cache
+ require_relative "cli/cache"
+ Cache.new(options).run
end
- map %w[cache pack] => :package
+
+ map aliases_for("cache")
desc "exec [OPTIONS]", "Run the command in context of the bundle"
method_option :keep_file_descriptors, :type => :boolean, :default => false
@@ -448,12 +471,13 @@ module Bundler
bundle exec you can require and call the bundled gems as if they were installed
into the system wide RubyGems repository.
D
- map "e" => "exec"
def exec(*args)
require_relative "cli/exec"
Exec.new(options, args).run
end
+ map aliases_for("exec")
+
desc "config NAME [VALUE]", "Retrieve or set a configuration value"
long_desc <<-D
Retrieves or sets a configuration value. If only one parameter is provided, retrieve the value. If two parameters are provided, replace the
@@ -496,7 +520,8 @@ module Bundler
Bundler.ui.info "Bundler version #{Bundler::VERSION}#{build_info}"
end
end
- map %w[-v --version] => :version
+
+ map aliases_for("version")
desc "licenses", "Prints the license of all gems in the bundle"
def licenses
@@ -680,12 +705,17 @@ module Bundler
# Reformat the arguments passed to bundle that include a --help flag
# into the corresponding `bundle help #{command}` call
def self.reformatted_help_args(args)
- bundler_commands = all_commands.keys
+ bundler_commands = (COMMAND_ALIASES.keys + COMMAND_ALIASES.values).flatten
+
help_flags = %w[--help -h]
- exec_commands = %w[e ex exe exec]
+ exec_commands = ["exec"] + COMMAND_ALIASES["exec"]
+
help_used = args.index {|a| help_flags.include? a }
exec_used = args.index {|a| exec_commands.include? a }
+
command = args.find {|a| bundler_commands.include? a }
+ command = all_aliases[command] if all_aliases[command]
+
if exec_used && help_used
if exec_used + help_used == 1
%w[help exec]
@@ -790,7 +820,7 @@ module Bundler
Bundler::SharedHelpers.major_deprecation 2,\
"The `#{flag_name}` flag is deprecated because it relies on being " \
- "remembered across bundler invokations, which bundler will no longer " \
+ "remembered across bundler invocations, which bundler will no longer " \
"do in future versions. Instead please use `bundle config set #{name} " \
"'#{value}'`, and stop using this flag"
end