简体   繁体   English

如何在Thor方法中检索当前命令名称?

[英]How can I retrieve the current command name in a Thor method?

I have several Thor tasks depending on each other. 我有几个互相依赖的雷神任务。 I'd like to have access to the name of the one currently running so that I can use it in the logger messages. 我想访问当前正在运行的名称,以便可以在记录器消息中使用它。

I can use the self object to find the task name but that's a Thor::Sandbox::MyClass object and that piece of information is deeply positioned. 我可以使用self对象找到任务名称,但这是一个Thor::Sandbox::MyClass对象,并且该信息的位置很深。 Does anybody know a getter? 有人知道吸气剂吗? Something like: 就像是:

class MyCLI < Thor
  def hello
    puts "hello, I am the task #{self.taskname}"
  end
end

May be this would work: 也许这会工作:

def fun
 puts __method__
end

fun
#=> :fun

Also look in the caller method. 还要查看caller方法。 It returns the current execution stack as a string. 它以字符串形式返回当前执行堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM