是否可以创建一个接受命名空间的基于 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
此 thorfile 提供以下任务 ( thor -T
):
thor talk:formal:greet # says a formal hello
thor talk:greet # says hello
我也可以直接使用 thorfile 作为可执行文件:
./thorfile greet
其中显示:
你好!
我怎样才能./thorfile formal:greet
(或类似的东西)在 Formal 类中执行 greet 方法,以便显示:
晚上好!