从任务内访问 Rake 任务描述
在 rake 任务中如何查询描述?会给出的东西:
desc "Populate DB"
task populate: :environment do
puts task.desc # "Populate DB"
end
Within a rake task how does one query the description? Something that would give:
desc "Populate DB"
task populate: :environment do
puts task.desc # "Populate DB"
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
task
必须定义为任务块的参数。编辑:
该解决方案适用于 rake 0.8.7。至少 rake 0.9.2.2 需要额外的
Rake::TaskManager.record_task_metadata = true
(我只检查了这两个版本)。具有自适应功能的独立 ruby 脚本:
原因:在
rake/task_manager.rb
第 30 行(rake 0.9.2.2)是一个检查默认
false
在第 305 行设置.comment 与
.full_comment
对于那些想知道的人,
.comment
打印第一行并.full_comment
将打印所有行(对于多行desc
),并在返回的字符串中用\n
指示新行。请参阅此处的文档:
#comment
#full_comment< /代码>
task
must be defined as a parameter for the task-block.Edit:
This solution works with rake 0.8.7. At least rake 0.9.2.2 need an additional
Rake::TaskManager.record_task_metadata = true
(I checked only this two versions).A stand alone ruby-script with adaption:
Reason: in
rake/task_manager.rb
line 30 (rake 0.9.2.2) is a checkThe default
false
is set in line 305..comment
vs.full_comment
For those wondering,
.comment
prints the first line and.full_comment
will print all lines (for multi-linedesc
), with new lines indicated with\n
in the returning String.See the docs here:
#comment
#full_comment
遇到类似的问题,我想向用户显示定制的帮助屏幕。这里的答案对我帮助很大。
这一点非常重要
在第一次定义任务之前完成
。然后你可以
通过调查 https:/ 来找到详细信息/github.com/jimweirich/rake/blob/master/lib/rake/application.rb#L284
Having a similar problem, that I wanted to show the user a customized help screen. The answer here helped me a lot.
It is very important that
is done before the first definition of tasks.
Then you can do
Details can be found by investigating https://github.com/jimweirich/rake/blob/master/lib/rake/application.rb#L284