有什么方法可以使Thor显示有关顶层命令的一般消息?
$my_command help
I'd like to show a welcome message here.
Commands:
my_command help [COMMAND]
答案 0 :(得分:1)
我能想到的最接近的事情是添加一个默认任务,并使用它来调用帮助任务。在不带任何参数的情况下调用$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...