thor wiki 页面Making an Exectable向您展示了如何创建一个由 thor 驱动的 CLI 命令,如下所示:
bash
./mythorcommand foo
这要求您将 thor 任务foo作为第一个参数传入。
我还可以使用 thor 的default_method运行不带任何参数的 thor 可执行文件:
bash
./mythorcommand
但是,我想传入一个变量字符串作为第一个参数:
bash
./mythorcommand "somevalue"
这不起作用,因为 thor 命令期望第一个参数是任务名称。有没有办法忽略任务名称并将第一个参数发送到默认方法?
如果此功能不存在,我认为添加一种将所有命令行参数传递给一个任务/方法的方法将非常有用:
class MyThorCommand < Thor
only_method :default
def default(*args)
puts args.inpsect
end
end
MyThorCommand.start