简体   繁体   English

是否有可能使用不是明确任务的Thor方法

[英]Is it possible to have a Thor method that is not an explicit task

I have a Thor script that uses several methods 我有一个使用多种方法的Thor脚本

class Update < Thor
   desc "do_it", "a simple task"
   def do_it
     puts i_did_it
   end

   # no desc here !!!
   def i_did_it
     "I did it"
   end 
end

Is this possible? 这可能吗? Without an explicit task, the tasks list can't be built correctly. 如果没有显式任务,则无法正确构建任务列表。

Thanks, 谢谢,

Tim 蒂姆

I was able to use the no_tasks block for this. 我能够使用no_tasks块。

class Update < Thor
   desc "do_it", "a simple task"
   def do_it
     puts i_did_it
   end

   # no desc here !!!
   no_tasks do
    def i_did_it
      "I did it"
    end
   end 
end

I tried this in 2018, no_tasks didn't work for me (maybe it is replaced with the following now): 我在2018年试过这个,no_tasks对我不起作用(也许它现在替换为以下内容):

As per Thor advice 根据Thor的建议

 Call desc if you want this method to be available as command or declare it inside a no_commands{} block.

So you can put the methods that you don't want to show for the CLI in a no_commands block as follows: 因此,您可以将不希望在CLI中显示的方法放在no_commands块中,如下所示:

 # no_commands is used to not show this as a command in our CLI gem

  no_commands { 
   # no desc here !!!
   # put here the methods that you don't want to show in your CLI

    def i_did_it
      "I did it"
    end

}

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

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