how to detect if --quiet option is specified with rake

别来无恙 提交于 2020-01-04 03:52:08

问题


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

In this case I would like to add one more case to filter out trace if --quiet option is specified.


回答1:


Rake.verbose provides option to check if --quiet mode is specified

Following simple rake file like produces output like this $rake --quiet false

$rake default

task :default do
  puts Rake.verbose
end

It is also possible to override the setting within rakefile using Rake.verbose(true|false)




回答2:


Looks like you can just call the method verbose in rake-10.0.4, at least.

With a task:

task :default do
  puts verbose
end

I get:

$ rake --silent
false
$ rake --quiet
false
$ rake --verbose
true


来源:https://stackoverflow.com/questions/9494693/how-to-detect-if-quiet-option-is-specified-with-rake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!