【问题标题】:How can one list method_options with thor -T?如何使用 thor -T 列出方法选项?
【发布时间】:2011-06-28 23:05:26
【问题描述】:

在使用 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 命令行工具时,我得到一个任务描述列表,如“import”,但没有描述“num_diamonds”等选项或其用法。

如何添加此类使用详情以便显示?

谢谢!

【问题讨论】:

    标签: ruby command-line thor


    【解决方案1】:

    默认情况下 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 方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多