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

ⅰ亾dé卋堺 提交于 2019-12-13 18:06:52

问题


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.


回答1:


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



回答2:


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

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


来源:https://stackoverflow.com/questions/7201205/how-do-i-know-if-a-rake-task-has-been-invoked-from-another-task-or-from-the-shel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!