Checking if Rake was called with Verbose or Trace

By Chas Lemley

Recently we needed to check whether a rake task was called with the –verbose or –trace flags.

For verbose you can do the following inside your rake task:

puts "ran with verbose" if verbose == true

Pretty simple, right? Be careful though, the default value for verbose is the symbol :default so using it in a predicate like if verbose will allow it to pass through. You will need to explicitly compare it to true.

Checking if your rake task was called with –trace is a bit more, well, verbose. Here is how you would do that:

puts "ran with trace" if Rake.application.options.trace == true
Written by Chas Lemley

Read more posts by Chas, and follow Chas on Twitter.

Interested in building something great?

Join us in building the worlds most loved hotel app.
View our open engineering positions.