Ruby “为什么?”;bundle exec“;吃我传递的参数?
当我使用Ruby “为什么?”;bundle exec“;吃我传递的参数?,ruby,gem,exec,bundle,bundler,Ruby,Gem,Exec,Bundle,Bundler,当我使用bundle exec调用命令时,它接受我传入的参数。例如: bundle exec my_command run --verbose 在本例中,--verbose用作绑定器参数,其中as应用于my_命令。我知道以下方法可行: bundle exec 'my_command run --verbose' 可以避免引用吗?我使用的命令已经有很多引号了。我原以为这样做会奏效,但没有: bundle exec -- my_command run --verbose 我没有看到关于bund
bundle exec
调用命令时,它接受我传入的参数。例如:
bundle exec my_command run --verbose
在本例中,--verbose
用作绑定器参数,其中as应用于my_命令
。我知道以下方法可行:
bundle exec 'my_command run --verbose'
可以避免引用吗?我使用的命令已经有很多引号了。我原以为这样做会奏效,但没有:
bundle exec -- my_command run --verbose
我没有看到关于bundler的很多文档。任何想法都将不胜感激。从中查看,默认行为是将bundle exec
之后的所有参数传递给Kernel.exec
,因此--verbose
参数将传递给您的命令,而不是bundle
bundle exec my_command run --verbose
将在bundle的上下文中运行以下命令
Kernel.exec('my_command', 'run', '--verbose')
及
由于未命名任何命令/脚本--,因此导致错误
在此处检查测试用例:
#!/usr/bin/env ruby
# coding: utf-8
# file: test.rb
p ARGV
测试:
这看起来像是在shell中将一个命令传递给另一个命令时的常见问题,而且看起来您已经接近我所使用的了。而不是使用:
bundle exec my_command run --verbose
或:
尝试:
使用
bundle exec--
会中断bundle exec的命令链exec
是bundle
的子命令,my_command
是exec
的参数。my_命令的参数
,无论是bundle
还是exec
都不需要知道它们,因此--
都会转到您想要断开参数链到bundle
的地方。我没有这个问题,您使用的bundler版本是什么?例如,我使用的是bundler版本1.3.5,运行特定的ActiveSupport::TestCasebundle exec ruby--test/unit/class_test.rb-n'/test_a_method/'
$ bundle exec ruby test.rb --verbose --arg1
["--verbose", "--arg1"]
bundle exec my_command run --verbose
bundle exec -- my_command run --verbose
bundle exec my_command -- run --verbose