问题
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