开发者

Can someone provide an example of Thor::HiddenTask usage?

I've just started using Thor. I've been looking around the documentation and can't find any code examples of making a task hidden. What I want is something like this,

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

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

But I don't want configure to show up in the list of tasks. It's kind of... private, you know? Can 开发者_StackOverflow社区someone give me an example of this?

In lib/thor/task.rb there is a subclass of Task called HiddenTask. Can anyone provide an example of how that subclass is used, and of how its method hidden? gets called? Thanks!

EDIT: Both of the answers below accomplish the goal mentioned in my question, but neither of them are an example of Thor:HiddenTask usage. I think I'm going to un-accept the answer to this question. They are both good answers, and the first one I actually used to achieve the desired behavior, but I would really like to see an example of a HiddenTask so that the answer corresponds to the question nicely.

Thanks!


In thor/spec/fixtures/script.thor you can find such usage:

desc "hidden TYPE", "this is hidden", :hide => true
def hidden(type)
  [type]
end


This is a little late but maybe this can help. Put your private methods in a "no_task" block like:

no_task do
  def my_private_method
    # Do something here
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜