繁体   English   中英

使Thor显示有关顶级命令的消息

[英]Make Thor show message for top level command

有什么方法可以使Thor显示有关顶层命令的一般消息?

$my_command help

I'd like to show a welcome message here.

Commands:
  my_command help [COMMAND]

我能想到的最接近的事情是添加一个默认任务,并使用它来调用帮助任务。 调用不带参数的$my_command时会收到此消息

require 'thor'
class MyCLI < Thor
  desc "hello NAME", "say hello to NAME"
  def hello(name)
    puts "Hello #{name}"
  end
  desc "greeting", "this is just a greeting"
  def greeting
    puts "Welcome to MyCLI"
    invoke :help
  end
  default_task :greeting
end

MyCLI.start(ARGV)

# $my_command
# output:

# Welcome to MyCLI
# Commands:
#   test.rb greeting        # this is just a greeting
#   test.rb hello NAME      # say hello to NAME
#   test.rb help [COMMAND]  # Describe available commands or one spec...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM