在 rake 任务中如何查询描述?会给出的东西:
desc "Populate DB"
task populate: :environment do
puts task.desc # "Populate DB"
end
task
必须定义为任务块的参数。
desc "Populate DB"
task :populate do |task|
puts task.comment # "Populate DB"
puts task.full_comment # "Populate DB"
puts task.name # "populate "
end
Edit:该解决方案适用于 rake 0.8.7。至少 rake 0.9.2.2 需要额外的Rake::TaskManager.record_task_metadata = true
(我只检查了这两个版本)。
具有适应性的独立 ruby 脚本:
gem 'rake' #'= 0.9.2.2'
require 'rake'
#Needed for rake/gem '= 0.9.2.2'
Rake::TaskManager.record_task_metadata = true
desc "Populate DB"
task :populate do |task|
p task.comment # "Populate DB"
p task.full_comment # "Populate DB"
p task.name # "populate "
end
if $0 == __FILE__
Rake.application['populate'].invoke() #all tasks
end
原因:在rake/task_manager.rb
第 30 行(rake 0.9.2.2)是一个检查
if Rake::TaskManager.record_task_metadata
add_location(task)
task.add_description(get_description(task))
end
默认false
在第 305 行设置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)