如何使用 thor -T 列出 method_options?

发布于 2024-11-17 17:58:49 字数 550 浏览 5 评论 0原文

当使用 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 

当我运行不带参数的 Diamond_importer 命令行工具或使用 -TI 时,会获取“导入”等任务的描述列表,但不会获取“num_diamonds”等选项的描述”或它们的用法。

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

谢谢!

When using thor I am used to writing code like this,

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 

When I run the diamond_importer command-line tool with no arguments, or with a -T I get a list of descriptions of tasks like "import", but not description of options like "num_diamonds" or their usage.

How can I add such usage details so that they will be displayed?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ら栖息 2024-11-24 17:58:49

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

by default class_option are included in the help, while method_options are only shown when help is called for that task...

% 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.

to change this you need to override the #help and/or #task_help methods of thor.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文