8

bin私はトールベースのRubyスクリプトを持っていますが、人々が何もしなくてもヒットできるように、人々のディレクトリにgemとしてデプロイしたいと考えています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:`method_missing' 内: nil:NilClass の未定義メソッド `start' (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'
        /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/bin/thor:6 から
        from /usr/bin/thor:19:in `load'
        /usr/bin/thor:19 から
4

3 に答える 3

12

シバンラインを作る

#!/usr/bin/env ruby

そして、スクリプトの最後に追加します

App.start
于 2010-12-01T14:18:44.303 に答える
1

これが役立つかもしれません: https://github.com/lastobelus/cleanthor

名前空間付きのサブコマンドを使用して、gem 用のトールベースの実行可能ファイルが必要でしたが、通常の ruby​​ gem lib/mygem/* / .rb 構造に従ってタスク ファイルを編成しました。

于 2012-12-07T06:17:29.940 に答える
0

スクリプトを実行可能にする

chmod +x mytool

#!/usr/bin/env thorの最初の行を作成しmytoolます。

于 2010-08-27T14:19:10.210 に答える