是否有可能创建一个接受命名空间的基于Thor的Ruby可执行文件?例如,允许命令行中的以下内容:./thorfile greet:formal
鉴于我有以下thorfile:
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
class TalkTasks < Thor
namespace "talk"
desc "greet", "says hello"
def greet
puts "Hello!"
end
class Formal < Thor
namespace "talk:formal"
desc "greet", "says a formal hello"
def greet
puts "Good evening!"
end
end
end
TalkTasks.start
Run Code Online (Sandbox Code Playgroud)
这个thorfile提供以下任务(thor -T):
thor talk:formal:greet # says a formal hello
thor talk:greet # says hello
Run Code Online (Sandbox Code Playgroud)
我也可以直接使用thorfile作为可执行文件:
./thorfile greet
Run Code Online (Sandbox Code Playgroud)
哪个显示:
你好!
我如何获得./thorfile formal:greet(或类似的)在Formal类中执行greet方法,以便显示:
晚上好!