summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-05-05 04:18:12 +0900
committerHomu <homu@barosl.com>2016-05-05 04:18:12 +0900
commitdcf08815dec4c8019a483eda44dca0ba44566eda (patch)
treecc655e8aa05111c25add80b303852f5f6405cf2d
parente6d734eb281994dc8237085b74b531f826bfea13 (diff)
parent62c3dbf4f8faa2c5dde77e890794f15f1868284a (diff)
downloadbundler-dcf08815dec4c8019a483eda44dca0ba44566eda.tar.gz
Auto merge of #4487 - b-ggs:show-executables-man-page, r=segiddins
Show executable's man page when --help or -h is present Fixes #4480, where `bundle exec foo --help` shows `bundle exec`'s man instead of `foo`'s man. @RochesterinNYC
-rw-r--r--lib/bundler/cli.rb30
-rw-r--r--spec/commands/exec_spec.rb108
2 files changed, 135 insertions, 3 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 9834277cd8..758decfa24 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -437,13 +437,37 @@ module Bundler
# into the corresponding `bundle help #{command}` call
def self.reformatted_help_args(args)
bundler_commands = all_commands.keys
+ help_flags = %w(--help -h)
+ exec_commands = %w(exec e)
+ help_used = args.select {|a| help_flags.include? a }
+ exec_used = args.select {|a| exec_commands.include? a }
command = args.select {|a| bundler_commands.include? a }
- if command.empty?
+ if exec_used.any? && help_used.any?
+ regex = /
+ ( # Matches `exec --help` or `exec --help foo`
+ (#{exec_commands.join("|")})
+ \s
+ (#{help_flags.join("|")})
+ (.+)*
+ )|
+ ( # Matches `--help exec` or `--help exec foo`
+ (#{help_flags.join("|")})
+ \s
+ (#{exec_commands.join("|")})
+ (.+)*
+ )
+ /x
+ arg_str = args.join(" ")
+ if arg_str =~ regex
+ %w(help exec)
+ else
+ args
+ end
+ elsif command.empty?
abort("Could not find command \"#{args.join(" ")}\".")
else
- command = command.first
+ ["help", command.first]
end
- ["help", command]
end
private
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index e2ae0aabbb..69e468e711 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -218,6 +218,114 @@ describe "bundle exec" do
expect(out).to include("bundler: exec needs a command to run")
end
+ describe "with help flags" do
+ describe "when exec is used" do
+ before(:each) do
+ install_gemfile <<-G
+ gem "rack"
+ G
+ end
+
+ it "shows executable's man page when --help is after the executable" do
+ bundle "exec cat --help"
+ expect(out).to include("Usage: cat [OPTION]... [FILE]...")
+ end
+
+ it "uses executable's original behavior for -h" do
+ bundle "exec cat -h"
+ expect(err).to include("cat: invalid option -- 'h'")
+ end
+
+ it "shows bundle-exec's man page when --help is between exec and the executable" do
+ with_fake_man do
+ bundle "exec --help cat"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when --help is before exec" do
+ with_fake_man do
+ bundle "--help exec"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when -h is before exec" do
+ with_fake_man do
+ bundle "-h exec"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when --help is after exec" do
+ with_fake_man do
+ bundle "exec --help"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when -h is after exec" do
+ with_fake_man do
+ bundle "exec -h"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+ end
+
+ describe "when e is used" do
+ before(:each) do
+ install_gemfile <<-G
+ gem "rack"
+ G
+ end
+
+ it "shows executable's man page when --help is after the executable" do
+ bundle "e cat --help"
+ expect(out).to include("Usage: cat [OPTION]... [FILE]...")
+ end
+
+ it "uses executable's original behavior for -h" do
+ bundle "e cat -h"
+ expect(err).to include("cat: invalid option -- 'h'")
+ end
+
+ it "shows bundle-exec's man page when --help is between exec and the executable" do
+ with_fake_man do
+ bundle "e --help cat"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when --help is before exec" do
+ with_fake_man do
+ bundle "--help e"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when -h is before exec" do
+ with_fake_man do
+ bundle "-h e"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when --help is after exec" do
+ with_fake_man do
+ bundle "e --help"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+
+ it "shows bundle-exec's man page when -h is after exec" do
+ with_fake_man do
+ bundle "e -h"
+ end
+ expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"]))
+ end
+ end
+ end
+
describe "with gem executables" do
describe "run from a random directory" do
before(:each) do