gpt4 book ai didi

ruby - 雷神 : How can I get my Thor task to display help when I have defined an argument?

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:30 25 4
gpt4 key购买 nike

我正在将一个小项目转换为使用 Thor,但由于心不在焉,我想使用内置帮助记录可用的任务。但是,如果我使用参数定义任务,任务级帮助将恢复为类的帮助 - 这意味着不会显示任务描述或预期参数的详细信息。

我希望能够有一个可以用参数而不是参数调用的方法,这样它就可以像这样使用

$ thor broke:foo hello
in a.thor broke:foo arg1=hello

我已将问题归结为以下 thorfile,除了损坏的帮助输出外,它可以正常工作。我已经删除了任何其他参数,因为它们对问题没有任何影响。第一个任务 ok:foo 将正常显示帮助,第二个任务 broke:foo 帮助不大:

class Ok < Thor
desc "foo", "ok test2"
def foo
puts "in a.thor ok:foo\n"
end
end
class Broke < Thor
argument :arg1, :type=>:string, :desc => "arg1"
desc "foo", "broke test1"
def foo
puts "in a.thor broke:foo arg1=#{self.arg1}\n"
end
end

请求帮助 ok:foo 任务方法给出:

$ thor help ok:foo
Usage:
thor ok:foo

ok test

请求帮助 broke:foo 任务的帮助不大:

$ thor help broke:foo
Tasks:
thor broke:foo ARG1 # broke test1
thor broke:help ARG1 [TASK] # Describe available tasks or one specific task

如何定义参数并显示正确的任务帮助?

最佳答案

你的 thorfile 中有一个小错误。

您有参数而不是method_option

这里是正确的版本:

class Ok < Thor
desc "foo", "ok test2"
def foo
puts "in a.thor ok:foo\n"
end
end
class Broke < Thor
method_option :arg1, :type=>:string, :desc => "arg1"
desc "foo", "broke test1"
def foo
puts "in a.thor broke:foo arg1=#{self.arg1}\n"
end
end

Wiki about method_option on github.com

关于ruby - 雷神 : How can I get my Thor task to display help when I have defined an argument?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11040420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com