加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将-version选项添加到Ruby Thor CLI中

发布时间:2020-12-16 21:40:59 所属栏目:百科 来源:网络整理
导读:如何在我的 Ruby Thor命令行界面应用程序中添加一个–version选项. 例如我想要能够运行 $thor_app --version thor_app version 1.0.0 这个问题与Run a CLI Thor app without arguments or task name有关,但特别是添加一个不需要任务的–version选项. 注意 这
如何在我的 Ruby Thor命令行界面应用程序中添加一个–version选项.

例如我想要能够运行

$thor_app --version
> thor_app version 1.0.0

这个问题与Run a CLI Thor app without arguments or task name有关,但特别是添加一个不需要任务的–version选项.

注意
这是写在self-answer format之后.添加答案和更新被鼓励

解决方法

我有一些运气与这种方法:
class CLI < Thor
  map %w[--version -v] => :__print_version

  desc "--version,-v","print the version"
  def __print_version
    puts FooBar::VERSION
  end
end

主要的下划线确保没有像你的版本一样的命令,并强制你的-version或者你的-v. desc内容将允许它显示为-v,–version,而不会暴露__print_version.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读