我正在使用 Thor 编写 CLI gem。现在我有两个子命令,我想用连字符连接它们的名称。但我不知道如何让它发挥作用。
这是主类
module CLI
class Base < Thor
desc "api-token COMMAND", "Configure the API token"
subcommand "api-token", ApiToken
这是子命令类
module CLI
class ApiToken < Thor
include Shared
namespace "api-token"
子命令显示在主 help
输出中,如果我输入
$ bundle exec bin/cli help api-token
它向我展示了子命令操作的正确输出。所以至少有东西在连接。
但是当我尝试使用命令时,这就是我所看到的
$ bundle exec bin/cli api-token set
> Could not find command "api-token".
如果我把它写成一个单词或使用下划线,命令就可以正常工作,但我真的更喜欢连字符。
最佳答案
不需要map
,只是
class Test < Thor
desc 'howto-dash', "dash in command name"
def howto_dash
puts "dashing through the snow"
end
end
输出:
> thor list
test
----
thor test:howto-dash # dash in command name
关于ruby - Thor 中带连字符的子命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40064574/