diff options
author | Homu <homu@barosl.com> | 2016-05-05 04:18:12 +0900 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-05-04 18:23:18 -0500 |
commit | 4b09898a8d7f73fd83a8e3d1840344ceb44b0964 (patch) | |
tree | 18df32a8bfe157014a4fc70206de008477e20a54 | |
parent | 4c9d42a62fd2074b898ffc7c5b4952859d91f4b4 (diff) | |
download | bundler-4b09898a8d7f73fd83a8e3d1840344ceb44b0964.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.rb | 30 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 108 |
2 files changed, 135 insertions, 3 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 0bd82fd128..c2d96d8112 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 |