ruby – 可以在不调用Thor的情况下调用可执行的Thor驱动的脚本吗?

我有一个基于Thor的 Ruby脚本,但是我想将它作为一个宝石部署在人们的bin目录中,人们可以在不需要做thto mytool的情况下进行打击.

所以相反他们只是使用mytool

这可能吗?

我知道有可能使用vanilla optparse,但如果可能,我宁愿使用Thor.

更新:这是我根据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': undefined method `start' for nil:NilClass (NoMethodError)
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:22:in `send'
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:22:in `run'
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:108:in `run'
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/invocation.rb:118:in `invoke_task'
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor.rb:246:in `dispatch'
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/base.rb:389:in `start'
        from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/bin/thor:6
        from /usr/bin/thor:19:in `load'
        from /usr/bin/thor:19

解决方法

做shebang线
#!/usr/bin/env ruby

然后在脚本的末尾添加

App.start

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...