簡體   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