我有一个使用多种方法的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
这可能吗?没有明确的任务,就无法正确构建任务列表。
谢谢,
蒂姆答案 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
}