【问题标题】:Is it possible to have a Thor method that is not an explicit task是否有可能有一个不是显式任务的 Thor 方法
【发布时间】:2011-11-01 00:31:21
【问题描述】:

我有一个使用多种方法的 Thor 脚本

类更新

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

谢谢,

提姆

【问题讨论】:

  • 我不明白为什么这不可能...您遇到了问题吗?

标签: ruby-on-rails ruby thor


【解决方案1】:

我可以为此使用 no_tasks 块。

类更新

【讨论】:

  • 我不确定 100% 肯定,但我认为私有方法也没有公开。
  • 我猜私有方法也可以,但这种方法不能很好地传达意图,...
【解决方案2】:

我在 2018 年尝试过,no_tasks 对我不起作用(现在可能已替换为以下内容):

根据雷神的建议

 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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多