我有一个基于 thor 的 Ruby 脚本,但我想将它作为一个 gem 部署在人们的bin
目录中,人们可以点击而无需执行thor mytool
.
所以他们只会使用mytool
这可能吗?
我知道香草有可能,optparse
但如果可能的话,我宁愿使用雷神。
更新:这是我根据 Thor 页面上的示例使用的代码,但出现以下错误:
#!/usr/bin/env thor
class App < Thor
map "-L" => :list
desc "install APP_NAME", "install one of the available apps"
method_options :force => :boolean, :alias => :string
def install(name)
user_alias = options[:alias]
if options.force?
# do something
end
# other code
end
desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
def list(search="")
# list everything
end
end
错误:
/usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/runner.rb:34:in `method_missing': nil:NilClass (NoMethodError) 的未定义方法`start' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:22:in `send' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:22:in `run' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:108:in `run' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/invocation.rb:118:in `invoke_task' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor.rb:246:in `dispatch' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/base.rb:389:in `start' 来自 /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/bin/thor:6 来自 /usr/bin/thor:19:in `load' 来自 /usr/bin/thor:19