9

当我使用它调用命令时,bundle exec它接受我传入的参数。一个例子是:

bundle exec my_command run --verbose

在这种情况下--verbose,它被用作捆绑器参数,它应该用于my_command. 我知道以下方法会起作用:

bundle exec 'my_command run --verbose'

是否可以避免引号?我使用的命令已经有很多引号。我希望这样的事情会起作用,但它没有:

bundle exec -- my_command run --verbose

对于捆绑器,我没有看到太多关于此的文档。任何想法将不胜感激。

4

2 回答 2

12

这看起来像是在 shell 中将一个命令传递给另一个命令时的一个常见问题,而且看起来你已经接近我使用的命令了。而不是使用:

bundle exec my_command run --verbose

或者:

bundle exec -- my_command run --verbose

尝试:

bundle exec my_command -- run --verbose

使用bundle exec --会破坏bundle exec. exec是 的子命令bundle并且my_command是 的参数exec。的参数my_command,嗯,既不需要bundle也不exec需要知道它们,所以--你想把参数链打断到bundle

于 2013-07-04T02:09:23.107 回答
2

从bundler 的源代码检查,在bundle execto之后传递所有参数是默认行为Kernel.exec,因此--verbose参数将传递给您的命令,而不是bundle.

bundle exec my_command run --verbose

将在 bundle 的上下文中运行以下内容

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

bundle exec -- my_command run --verbose

导致错误,因为没有命名命令/脚本--

在此处检查测试用例:

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

p ARGV

测试:

$ bundle exec ruby test.rb --verbose --arg1
["--verbose", "--arg1"]
于 2013-07-04T02:05:15.730 回答