summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-10-20 14:03:11 +0200
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-10-30 10:04:18 +0100
commite983b2946ffe30c9f8437dfe5679eeab1abaeec0 (patch)
tree91f63f62c095d6f6e299c7d444c0a92ed437ba4d
parentf7212773160d00d88f58c24147584cada0da5187 (diff)
downloadbundler-fix_help_with_command_aliases.tar.gz
Fix help with command aliasesfix_help_with_command_aliases
When using the `-h` flag with command aliases, bundler was showing a default help page instead of our manual, so that for example, `bundle help install` and `bundle install --help` output would be inconstent with `bundle i --help`. This commit fixes that.
-rw-r--r--lib/bundler/cli.rb22
-rw-r--r--spec/bundler/cli_spec.rb50
2 files changed, 70 insertions, 2 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index ea2d5c9de3..bacbb8dbde 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -36,8 +36,22 @@ 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.slice(command_name).invert
+ COMMAND_ALIASES.select {|k, _| k == command_name }.invert
end
def initialize(*args)
@@ -694,13 +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 = ["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! ""