我在这里看到过类似的问题,无法找到答案,我刚刚开始研发。我有一个佣金任务:
namespace:generate do
desc "Export to txt"
task :txt => :environment do |t, args|
puts "testing #{args}"
end
end
当我从命令行执行此操作时:
rake generate:txt
我得到testing {}
当我尝试将值作为参数注入时:
rake generate:txt[testvalue]
或
rake generate:txt testvalue
第一个没有做同样的输出testing {}
第二个我得到一个错误。那么我以哪种方式调用命令,以便用一些值填充args?
答案 0 :(得分:1)
namespace:generate do
desc "Export to txt"
task :txt, [:arg1] => :environment do |t, args|
puts "testing #{args[:arg1]}"
end
end
rake generate:csv arg1="value"
答案 1 :(得分:1)
task :environment do
puts "setting up env"
end
namespace :generate do
desc "Export to txt"
task :txt, [:filename] => :environment do |t, args|
puts "testing #{args}"
end
end
然后
% rake generate:txt['foo']
setting up env
testing {:filename=>"foo"}