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_e开发者_StackOverflow社区lse
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
.
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
You could look what was passed to ARGV. For example:
task :something_else do
if ARGV[0] == 'something_else'
puts "Verbose Stuff!"
end
end
精彩评论