summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-05-21 15:32:06 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-05-23 13:46:52 -0500
commit53845c5c9dcdd6fd7acd7aaf7acf244b103cdd83 (patch)
treed55a7e00b44ec3a3087de567df2a914fe55f77cc
parent7351eddd5b70f1fa707404386f2afe34a6127cf0 (diff)
downloadbundler-seg-exec-help-with-dash.tar.gz
[CLI] Only redirect to help whel first two args are help and execseg-exec-help-with-dash
-rw-r--r--lib/bundler/cli.rb31
-rw-r--r--lib/bundler/friendly_errors.rb2
-rw-r--r--spec/commands/exec_spec.rb144
-rw-r--r--spec/support/helpers.rb2
4 files changed, 72 insertions, 107 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 1171a9cdd9..f2af5d71f7 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 f7a10d0035..a01c03f25c 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 6e16ae6492..75ee592826 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -80,7 +80,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__)