3

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.

Bryan Ash
  • 4,385
  • 3
  • 41
  • 57
harsha
  • 933
  • 1
  • 12
  • 26

2 Answers2

6

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)

harsha
  • 933
  • 1
  • 12
  • 26
1

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
Ryan McCuaig
  • 2,229
  • 15
  • 21