如何检测是否使用 rake 指定了 --quiet 选项 [英] how to detect if --quiet option is specified with rake
本文介绍了如何检测是否使用 rake 指定了 --quiet 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测是否使用 rake 指定了 --quiet 选项.
how to detect of if --quiet option is specified with rake.
目的是根据类别过滤自定义消息.
Intention is to filter custom messages based on category.
class Category
INFO = 1
WARNING = 2
ERROR = 3
end
@trace = true
task :silent do
@trace = false
end
def trace(msg, category=Category::INFO)
return if (@trace == nil)
return if ((@trace == false) && (category == Category::INFO))
puts msg
end
在这种情况下,如果指定了 --quiet 选项,我想再添加一个案例来过滤掉跟踪.
In this case I would like to add one more case to filter out trace if --quiet option is specified.
推荐答案
Rake.verbose 提供检查是否指定了 --quiet 模式的选项
Rake.verbose provides option to check if --quiet mode is specified
遵循简单的 rake 文件,如产生这样的输出$rake --安静假
Following simple rake file like produces output like this $rake --quiet false
$rake 默认
task :default do
puts Rake.verbose
end
也可以使用 Rake.verbose(true|false) 覆盖 rakefile 中的设置
It is also possible to override the setting within rakefile using Rake.verbose(true|false)
这篇关于如何检测是否使用 rake 指定了 --quiet 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文