rakefile task does not accept second parameters

时间:2019-03-19 15:16:09

标签: ruby rake rakefile

I have piece of code from my rakefile. Few tasks have to have multiple parameters.

desc 'confidential'
  task :task1, [:targetPrj, :arg1] do |t,args|
  args.with_defaults(:arg1 => "0")
  TARGET_PROJECT = args[:targetPrj]
  TEST_SW = args[:emcTest]
  makeApp(t)
end

If I call rake task1[TARGET _1] everything is OK, but if I add second parameter rake task1[TARGET _1, 5] then I get:

Rake aborted!
Don't know how to build task task1[TARGET_1, '

I really do not know what is wrong?

2 个答案:

答案 0 :(得分:1)

The parameters should be separated by commas without spaces:

task1[TARGET_1,5]

答案 1 :(得分:0)

命令行参数用空格分隔,并且rake将每个参数视为一个单独的任务。这将运行任务foobar

rake foo bar

如果您有:

rake task1[TARGET_1, 5]

然后,rake得到两个参数:task1[TARGET_1,5]。尝试解析这些字符串会导致错误。

要获得正确的结果,可以删除空格,转义空格或将引号引起来:

rake task1[TARGET_1,5]
rake task1[TARGET_1,\ 5]
rake "task1[TARGET_1, 5]"

请注意,此行为不是特定于rake的,这就是命令行参数通常的工作方式。