summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-10-30 10:16:36 +0000
committerBundlerbot <bot@bundler.io>2019-10-30 10:16:36 +0000
commit5bc9c5868307679b79cdb7e4026da5f9e3888c63 (patch)
tree91f63f62c095d6f6e299c7d444c0a92ed437ba4d
parent5ba1360de631e2fabf2bfa998b104c4355c58b13 (diff)
parente983b2946ffe30c9f8437dfe5679eeab1abaeec0 (diff)
downloadbundler-5bc9c5868307679b79cdb7e4026da5f9e3888c63.tar.gz
Merge #7388
7388: Fix help with command aliases r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that the output of `bundle help install` and `bundle install --help` was inconstent with `bundle i --help`, and the same issue with all of the other command aliases. ### What was your diagnosis of the problem? My diagnosis was that the command reformatting so that `bundle <cmd> --help` "redirects" to `bundle help <cmd>` was ignoring command aliases. ### What is your fix for the problem, implemented in this PR? My fix is to make this logic aware of command aliases. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
-rw-r--r--lib/bundler/cli.rb57
-rw-r--r--spec/bundler/cli_spec.rb50
2 files changed, 96 insertions, 11 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 39f42c9a70..bacbb8dbde 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -9,9 +9,16 @@ 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
@@ -29,6 +36,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
@@ -152,7 +177,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")
@@ -160,6 +184,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.
@@ -221,7 +247,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")
@@ -235,6 +260,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
@@ -326,7 +353,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"
@@ -436,7 +463,8 @@ module Bundler
require_relative "cli/cache"
Cache.new(options).run
end
- map %w[package pack] => :cache
+
+ map aliases_for("cache")
desc "exec [OPTIONS]", "Run the command in context of the bundle"
method_option :keep_file_descriptors, :type => :boolean, :default => false
@@ -446,12 +474,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
@@ -494,7 +523,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
@@ -678,12 +708,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]
diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb
index 02e5155733..ddcd699d6c 100644
--- a/spec/bundler/cli_spec.rb
+++ b/spec/bundler/cli_spec.rb
@@ -27,6 +27,56 @@ RSpec.describe "bundle executable" do
expect(out).to eq("Hello, world")
end
+ describe "aliases" do
+ it "aliases e to exec" do
+ bundle "e --help"
+
+ expect(out).to include("BUNDLE-EXEC")
+ end
+
+ it "aliases ex to exec" do
+ bundle "ex --help"
+
+ expect(out).to include("BUNDLE-EXEC")
+ end
+
+ it "aliases exe to exec" do
+ bundle "exe --help"
+
+ expect(out).to include("BUNDLE-EXEC")
+ end
+
+ it "aliases c to check" do
+ bundle "c --help"
+
+ expect(out).to include("BUNDLE-CHECK")
+ end
+
+ it "aliases i to install" do
+ bundle "i --help"
+
+ expect(out).to include("BUNDLE-INSTALL")
+ end
+
+ it "aliases ls to list" do
+ bundle "ls --help"
+
+ expect(out).to include("BUNDLE-LIST")
+ end
+
+ it "aliases package to cache" do
+ bundle "package --help"
+
+ expect(out).to include("BUNDLE-CACHE")
+ end
+
+ it "aliases pack to cache" do
+ bundle "pack --help"
+
+ expect(out).to include("BUNDLE-CACHE")
+ end
+ end
+
context "with no arguments" do
it "prints a concise help message", :bundler => "3" do
bundle! ""