diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index d86441f5aee..1b913024e2a 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -319,6 +319,8 @@ def info(gem_name) "Specify a different shebang executable name than the default (usually 'ruby')" method_option "standalone", :type => :boolean, :banner => "Make binstubs that can work without the Bundler runtime" + method_option "all", :type => :boolean, :banner => + "Install binstubs for all gems" def binstubs(*gems) require "bundler/cli/binstubs" Binstubs.new(options, gems).run diff --git a/lib/bundler/cli/binstubs.rb b/lib/bundler/cli/binstubs.rb index 449204d821a..266396eedc6 100644 --- a/lib/bundler/cli/binstubs.rb +++ b/lib/bundler/cli/binstubs.rb @@ -16,7 +16,13 @@ def run Bundler.settings.set_command_option_if_given :shebang, options["shebang"] installer = Installer.new(Bundler.root, Bundler.definition) - if gems.empty? + installer_opts = { :force => options[:force], :binstubs_cmd => true } + + if options[:all] + raise InvalidOption, "Cannot specify --all with specific gems" unless gems.empty? + @gems = Bundler.definition.specs.map(&:name) + installer_opts.delete(:binstubs_cmd) + elsif gems.empty? Bundler.ui.error "`bundle binstubs` needs at least one gem to run." exit 1 end @@ -35,7 +41,7 @@ def run installer.generate_standalone_bundler_executable_stubs(spec) end else - installer.generate_bundler_executable_stubs(spec, :force => options[:force], :binstubs_cmd => true) + installer.generate_bundler_executable_stubs(spec, installer_opts) end end end diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index 8157173b424..ad859a21d51 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -39,6 +39,18 @@ expect(bundled_app("bin/rails")).to exist end + it "allows installing all binstubs" do + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + bundle! :binstubs, :all => true + + expect(bundled_app("bin/rails")).to exist + expect(bundled_app("bin/rake")).to exist + end + it "displays an error when used without any gem" do install_gemfile <<-G source "file://#{gem_repo1}" @@ -50,6 +62,17 @@ expect(out).to include("`bundle binstubs` needs at least one gem to run.") end + it "displays an error when used with --all and gems" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "binstubs rack", :all => true + expect(last_command).to be_failure + expect(last_command.bundler_err).to include("Cannot specify --all with specific gems") + end + context "when generating bundle binstub outside bundler" do it "should abort" do install_gemfile <<-G