小编Leo*_*man的帖子

在 Ruby 的 Thor 上,如何显示应用程序内的命令用法

我正在使用 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)

执行此操作的正确方法是什么?

ruby thor

3
推荐指数
1
解决办法
746
查看次数

标签 统计

ruby ×1

thor ×1