Why does "bundle exec" eat the parameters I pass in? Why does "bundle exec" eat the parameters I pass in? ruby ruby

Why does "bundle exec" eat the parameters I pass in?


This looks like what is a common problem when passing one command to another in the shell, and it looks like you're close to what I'd use. Instead of using:

bundle exec my_command run --verbose

Or:

bundle exec -- my_command run --verbose

Try:

bundle exec my_command -- run --verbose

Using bundle exec -- breaks the command-chain for bundle exec. exec is a sub-command for bundle and my_command is a parameter for exec. The parameters for my_command, well, neither bundle or exec needs to know about them so the -- goes where you want to break that chain of parameters to bundle.


Inspecting from source of bundler, it is default behavior to pass all the parameters after bundle exec to Kernel.exec, so the --verbose parameters will be passed to your command, not bundle.

bundle exec my_command run --verbose

will run the following under the context of bundle

Kernel.exec('my_command', 'run', '--verbose')

and

bundle exec -- my_command run --verbose

results in an error because no command/script is named --.

Check the test case here:

#!/usr/bin/env ruby# coding: utf-8# file: test.rbp ARGV

test:

$ bundle exec ruby test.rb --verbose --arg1["--verbose", "--arg1"]