【问题标题】:Passing parameters to Rake将参数传递给 Rake
【发布时间】:2015-02-23 00:22:21
【问题描述】:

我看到了关于如何pass parameters to rake 的热门帖子。我从该帖子中复制粘贴的示例代码,但它对我不起作用:

Rakefile.rb:

require 'rake'

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

然后在命令行我运行

rake my_task[1,2]

错误

rake 中止!不知道如何构建任务'my_task[1'

逗号好像被截断了。它可能需要逃脱,但我不知道如何。我尝试了rake my_task[1\,2],它只在错误中添加了一个斜杠。答案有 700 多个赞成票,所以……我做错了什么?

rake --version : 耙子,版本 10.3.2

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

【问题讨论】:

  • 你用的是什么外壳?尝试引用 Rake 的参数:rake 'my_task[1,2]'
  • @AndrewMarshall - 我试过cmd,它工作正常。所以它绝对是我的外壳。当我在两种模式之间切换时,“Console2 和 PS”都说“Windows Powershell”。你的方法奏效了!如果您将此作为答案,我会标记它。谢谢!

标签: ruby powershell rake


【解决方案1】:

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

rake 'my_task[1,2]'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2012-10-29
    • 2016-04-08
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 2011-07-02
    相关资源
    最近更新 更多