支持参数的Rake任务
最近想用rake来写一个数据迁移脚本。考虑到重用性,脚本必须支持参数。于是上网试着搜索rake中的任务如何加入参数。发现rake还真的支持参数哦。唉,真是后知后觉。
马上动手作了一个demo。Works!
记录一下
Rake任务代码:
desc “Test params”
task :test_p, [:username,:password] => :environment do |t, args|
require ‘pp’
pp args
end
运行命令:
rake tapd3:test_p['frankychen','1234'] –trace
输出:
{:password=>”1234″, :username=>”frankychen”}
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Thanks for posting, I really liked reading your most recent post. I think you should post more often, you evidently have talent for blogging!