ruby - 如何使用 thor -T 列出 method_options?

标签 ruby command-line thor

在使用thor的时候我习惯这样写代码,

desc "import", "Import diamonds from the south."                   
method_option :num_diamonds, :type => :numeric, :default => nil               
def import
  diamond_importer = DiamondImporter.new
  diamond_importer.update_maps                                     
  diamond_importer.process_diamonds(options)                               
end 

当我运行不带参数或带 -T 的 diamond_importer 命令行工具时,我得到一个任务描述列表,如“导入”,但没有描述选项,如“num_diamonds”或其用法。

如何添加此类使用详细信息以便显示它们?

谢谢!

最佳答案

默认情况下,class_option 包含在帮助中,而 method_options 仅在为该任务调用帮助时显示...

% diamond_importer help #shows class options as help, and 1 line per task
% diamond_importer help import #shows the class options and method options for the "import" task.

要更改它,您需要覆盖 thor.rb 的#help 和/或#task_help 方法

关于ruby - 如何使用 thor -T 列出 method_options?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6514109/

相关文章:

ruby - 根据 Ruby 中的字符拆分 URL

Ruby:CSV 编码:IlegalFormatError

java - java 帮助中的命令行参数

c - 在 C 中通过命令行传递整数?

带有命名空间的基于 Ruby Thor 的可执行文件

ruby 电子表格行背景色

php - 通过 exec() 从 php 调用 php 没有结果

ruby - Thor - 方法中无法识别命令行选项

ruby-on-rails - 在我的 rspec 中要求 thor 任务导致未定义的方法

ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作