我正在使用 Ruby 和 Thor 构建 CLI,如果没有传递任何选项,我想在屏幕上打印命令用法。
下面的伪代码行中的一些内容:
Class Test < Thor
desc 'test', 'test'
options :run_command
def run_command
if options.empty?
# Print Usage
end
end
end
Run Code Online (Sandbox Code Playgroud)
我目前正在使用以下 hack(我并不为此感到自豪!=P):
Class Test < Thor
desc 'test', 'test'
options :run_command
def run_command
if options.empty?
puts `my_test_command help run_command`
end
end
end
Run Code Online (Sandbox Code Playgroud)
执行此操作的正确方法是什么?