我有一個基於thor的Ruby腳本,但我想將它部署爲人們的bin
目錄中的寶石,人們可以在不需要做thor mytool
的情況下打開它。可能調用可執行文件無需調用thor的託管腳本?
所以不是他們剛剛用mytool
這可能嗎?
我知道這是可能的香草optparse
但我寧願使用雷神如果可能的話。
更新:這是我根據雷神頁的示例使用的代碼,但我得到的錯誤如下:
#!/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
這很好。總結:調用該文件,使其可執行,更改爆炸線以使用Ruby,如上所示,將App.start添加到最後。贏得! – 2010-12-02 04:22:44
記錄在哪裏?我不得不在整個網絡上搜索例子來找出shebang-start的伎倆。 – 2011-01-08 18:23:01
這不是真的。 shebang是製作可執行腳本的標準方式。在http://rdoc.info/gems/thor/0.14.6/Thor/Base/ClassMethods:start中記錄了混入Thor子類中的「start」類方法。總的來說,我確實同意Thor的文檔雖然有點不準確。 – Simon 2011-01-08 19:15:34