1

我刚开始使用Thor。我一直在查看文档,找不到任何隐藏任务的代码示例。我想要的是这样的,

desc "configure", "Do the configuration"
def configure
  # configuration
end

desc "import", "Import the stuff"
  invoke :configure
  # import the stuff
end

但我不希望配置显示在任务列表中。这有点……私人的,你知道吗?有人可以给我一个例子吗?

在 lib/thor/task.rb 中有一个名为 HiddenTask 的 Task 子类。谁能提供一个如何使用该子类以及如何hidden?调用其方法的示例?谢谢!

编辑:下面的两个答案都实现了我的问题中提到的目标,但它们都不是 Thor:HiddenTask 用法的示例。我想我将不接受这个问题的答案。它们都是很好的答案,也是我实际用来实现所需行为的第一个答案,但我真的很想看到一个 HiddenTask 的示例,以便答案很好地对应于问题。

谢谢!

4

2 回答 2

6

thor/spec/fixtures/script.thor你可以找到这样的用法:

desc "hidden TYPE", "this is hidden", :hide => true
def hidden(type)
  [type]
end
于 2011-07-30T10:26:22.767 回答
2

这有点晚了,但也许这会有所帮助。将您的私有方法放在“no_task”块中,例如:

no_task do
  def my_private_method
    # Do something here
  end
end
于 2011-06-30T19:32:03.143 回答