我正在寻找一种方法来创建一个命令行雷神应用程序,该应用程序将运行不带任何参数的默认方法。我摆弄了 Thor 的 default_method 选项,但仍然要求我传递一个参数。我找到了一个类似案例 https://stackoverflow.com/questions/3584731/possible-to-call-executable-thor-powered-script-without-calling-thor有人想要运行带有参数但没有任务名称的 CLI Thor 任务。
我想运行一个没有任务名称和参数的任务。这样的事可能吗?
似乎正确的雷神方法是使用default_task
:
class Commands < Thor
desc "whatever", "The default task to run when no command is given"
def whatever
...
end
default_task :whatever
end
Commands.start
如果出于某种原因这不是您所需要的,您应该能够执行类似的操作
class Commands < Thor
...
end
if ARGV.empty?
# Perform the default, it doesn't have to be a Thor task
Commands.new.whatever
else
# Start Thor as usual
Commands.start
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)