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

时间:2011-11-01 00:31:21

标签: ruby-on-rails ruby thor

我有一个使用多种方法的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

这可能吗?没有明确的任务,就无法正确构建任务列表。

谢谢,

蒂姆

2 个答案:

答案 0 :(得分:5)

我能够使用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

答案 1 :(得分:1)

我在2018年试过这个,no_tasks对我不起作用(也许现在替换为以下内容):

根据Thor的建议

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

因此,您可以将不希望在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

}