diff options
author | Homu <homu@barosl.com> | 2016-05-24 11:49:51 +0900 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-05-25 13:57:25 -0500 |
commit | 7e6aa5a5a98493e15286bc78d4049345a2c41ac9 (patch) | |
tree | b2eb641c53f13120ab163a48fc11136239f7bbb6 | |
parent | fd73d3a11f467a6a446e8c0f42c418f54a5559c2 (diff) | |
download | bundler-7e6aa5a5a98493e15286bc78d4049345a2c41ac9.tar.gz |
Auto merge of #4598 - bundler:seg-exec-help-with-dash, r=RochesterinNYC
[CLI] Only redirect to help when first two args are help and exec
Closes #4596.
\c @RochesterinNYC @b-ggs
-rw-r--r-- | lib/bundler/cli.rb | 31 | ||||
-rw-r--r-- | lib/bundler/friendly_errors.rb | 2 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 144 | ||||
-rw-r--r-- | spec/support/helpers.rb | 2 |
4 files changed, 72 insertions, 107 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index dc006f2959..aaea45ccab 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -438,35 +438,20 @@ module Bundler 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 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 + exec_commands = %w(e ex exe 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 } + if exec_used && help_used + if exec_used + help_used == 1 %w(help exec) else args end - elsif command.empty? + elsif command.nil? abort("Could not find command \"#{args.join(" ")}\".") else - ["help", command.first] + ["help", command || args].flatten.compact end end diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index b453e8e625..9510ce1a1e 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -69,7 +69,7 @@ module Bundler Error details #{e.class}: #{e.message} - #{e.backtrace.join("\n ")} + #{e.backtrace && e.backtrace.join("\n ")} #{Bundler::Env.new.report(:print_gemfile => false, :print_gemspecs => false).gsub(/\n/, "\n ").strip} --- TEMPLATE END ---------------------------------------------------------------- diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 69e468e711..ef59c49580 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -219,109 +219,89 @@ describe "bundle exec" do end describe "with help flags" do - describe "when exec is used" do - before(:each) do - install_gemfile <<-G - gem "rack" - G - end + each_prefix = proc do |string, &blk| + 1.upto(string.length) {|l| blk.call(string[0, l]) } + end + each_prefix.call("exec") do |exec| + describe "when #{exec} is used" do + before(:each) do + install_gemfile <<-G + gem "rack" + G + + create_file("print_args", <<-'RUBY') + #!/usr/bin/env ruby + puts "args: #{ARGV.inspect}" + RUBY + bundled_app("print_args").chmod(0755) + 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 "shows executable's man page when --help is after the executable" do + bundle "#{exec} print_args --help" + expect(out).to eq('args: ["--help"]') + 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 executable's man page when --help is after the executable and an argument" do + bundle "#{exec} print_args foo --help" + expect(out).to eq('args: ["foo", "--help"]') - 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 + bundle "#{exec} print_args foo bar --help" + expect(out).to eq('args: ["foo", "bar", "--help"]') - it "shows bundle-exec's man page when --help is before exec" do - with_fake_man do - bundle "--help exec" + bundle "#{exec} print_args foo --help bar" + expect(out).to eq('args: ["foo", "--help", "bar"]') 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" + it "shows executable's man page when the executable has a -" do + FileUtils.mv(bundled_app("print_args"), bundled_app("docker-template")) + bundle "#{exec} docker-template build discourse --help" + expect(out).to eq('args: ["build", "discourse", "--help"]') 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" + it "shows executable's man page when --help is after another flag" do + bundle "#{exec} print_args --bar --help" + expect(out).to eq('args: ["--bar", "--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" + it "uses executable's original behavior for -h" do + bundle "#{exec} print_args -h" + expect(out).to eq('args: ["-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" + 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 - 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" + 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 - 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" + 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 - 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" + 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 - 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" + 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 - expect(out).to include(%(["#{root}/lib/bundler/man/bundle-exec"])) end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 5a5d07300b..ea183450bd 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -83,7 +83,7 @@ module Spec with_sudo = options.delete(:sudo) sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo - options["no-color"] = true unless options.key?("no-color") || %w(exec conf).include?(cmd.to_s[0..3]) + options["no-color"] = true unless options.key?("no-color") || cmd.to_s.start_with?("exec", "exe", "ex", "e", "conf") bundle_bin = File.expand_path("../../../exe/bundle", __FILE__) |