运行不带参数或任务名称的 CLI Thor 应用程序
我正在寻找一种方法来创建一个命令行雷神应用程序,该应用程序将运行不带任何参数的默认方法。我摆弄了 Thor 的 default_method 选项,但仍然要求我传递一个参数。我发现了一个类似案例,有人想要运行带参数但不带任务名称的 CLI Thor 任务。
我想运行一个没有任务名称和参数的任务。这样的事可能吗?
I'm looking for a way to create a command-line thor app that will run a default method without any arguments. I fiddled with Thor's default_method option, but still requires that I pass in an argument. I found a similar case where someone wanted to run a CLI Thor task with arguments but without a task name.
I'd like to run a task with no task name and no arguments. Is such a thing possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎执行此操作的正确雷神方法是使用
default_task
:如果出于某种原因这不是您所需要的,您应该能够执行类似的操作
It seems the proper Thor-way to do this is using
default_task
:If for whatever reason that isn't what you need, you should be able to do something like
有点黑客,但无论如何只有一个定义的操作,我只是将操作名称添加到传入的
ARGV
数组中:然后我通过传入 ARGV 来启动该类:
Kind of hackish, but where there's only one defined action anyway, I just prepended the action name to the
ARGV
array that gets passed in:Then where I start the class by passing in ARGV:
虽然它有点hackish,但我通过捕获选项作为参数本身解决了类似的问题:
当在
Thor::Group
中运行时,此方法在其他方法之前执行,让我欺骗程序做出响应到像论证这样的选项。此代码来自 https://github.com/neverstopbuilding/blam。
While it is a little hackish, I solved a similar problem by catching the option as the argument itself:
When running in a
Thor::Group
this method is executed before others and lets me trick the program into responding to an option like argument.This code is from https://github.com/neverstopbuilding/blam.