将参数传递给 Rake

Passing parameters to Rake

我看过流行的post如何pass parameters to rake。我从那个 post 复制粘贴的示例代码,但它对我不起作用:

Rakefile.rb:

require 'rake'

task :my_task, [:arg1, :arg2] do |t, args|
  puts "Args were: #{args}"
end

然后在命令行我运行

耙子my_task[1,2]

错误

rake aborted! Don't know how to build task 'my_task[1'

看起来逗号是 t运行。它可能需要转义,但我不知道如何转义。我试过 rake my_task[1\,2] 并且它只在错误中添加了一个斜杠。答案有超过 700 个赞成票所以...我做错了什么?

rake --version : 耙子,版本 10.3.2

我正在使用 Console2 shell,当我启动一个新的终端实例时它显示 "Windows PowerShell"。

您的 shell 可能将 Rake 的参数解释为特殊的东西,因此引用它以避免发生这种情况:

rake 'my_task[1,2]'