【问题标题】:Why does "bundle exec" eat the parameters I pass in?为什么“bundle exec”会吃掉我传入的参数?
【发布时间】:2013-07-04 01:04:34
【问题描述】:

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

bundle exec my_command run --verbose

在这种情况下,--verbose 用作捆绑程序参数,而它应该用于my_command。我知道以下方法可行:

bundle exec 'my_command run --verbose'

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

bundle exec -- my_command run --verbose

我没有看到太多关于 bundler 的文档。任何想法将不胜感激。

【问题讨论】:

  • 我没有这个问题,你用的是什么版本的bundler?
  • 我使用的是捆绑器版本 1.3.5

标签: ruby gem exec bundle bundler


【解决方案1】:

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

bundle exec my_command run --verbose

或者:

bundle exec -- my_command run --verbose

试试:

bundle exec my_command -- run --verbose

使用bundle exec -- 会破坏bundle exec 的命令链。 execbundle 的子命令,my_commandexec 的参数。 my_command 的参数,嗯,bundleexec 都不需要知道它们,所以 -- 去你想要打破参数链到 bundle 的地方。

【讨论】:

  • 例如运行特定的 ActiveSupport::TestCase bundle exec ruby -- test/unit/class_test.rb -n '/test_a_method/'
【解决方案2】:

source of bundler 进行检查,默认行为是将bundle exec 之后的所有参数传递给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"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 2012-05-26
    • 1970-01-01
    • 2016-09-16
    相关资源
    最近更新 更多