【发布时间】:2017-09-12 02:01:43
【问题描述】:
我正在使用 Ruby 和 Thor 构建一个 CLI,如果没有通过任何选项,我想在屏幕上打印命令用法。
下面的伪代码行:
Class Test < Thor
desc 'test', 'test'
options :run_command
def run_command
if options.empty?
# Print Usage
end
end
end
我目前正在使用以下 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
这样做的正确方法是什么?
【问题讨论】: