Kostas
Kostas

Reputation: 8595

How do I know if a rake task has been invoked from another task or from the shell?

Let's say we have:

task :something => [:something_else] do
  # some of stuff
end

task :something_else do
  # some verbose stuff
  # some quiet stuff
end

Now I want something_else to do the verbose stuff when called from the shell (rake something_else) and the silent ones when called as a dependency to rake something.

Upvotes: 2

Views: 200

Answers (2)

phoet
phoet

Reputation: 18835

i think it might be a better idea to work with parameters or different tasks instead.

one thing that you could do is look for top-level task like that:

task :something_else do |t|
  puts "some verbose stuff" if t.application.top_level_tasks.include? 'something_else'
  puts "some quiet stuff"
end

Upvotes: 2

Tatu Lahtela
Tatu Lahtela

Reputation: 4554

You could look what was passed to ARGV. For example:

task :something_else do
    if ARGV[0] == 'something_else'
       puts "Verbose Stuff!"
    end
end

Upvotes: 1

Related Questions