bar_1

contents_map

2018年12月21日金曜日

Thor 実行ファイルを作る Making An Executable

実行ファイルを作る Making An Executable

あなたはスクリプトをひとつの実行可能コマンドとして作りたいかもしれない. これをThorで行うには:
You may want to make a script as an executable command. To do this with Thor:
  • RubyのShebang行 (訳注: #! で始まる実行スクリプトの最初の一行目) を入れる.
  • スクリプトの中で require "thor" する.
  • あなたのThorクラスを定義する.
  • #{YourThorClassname}.start を最下行に書く (訳注: .start(ary)とすると明示的に渡せる. この例のようにaryを指定しないとARGVが自動で使われる).
  • include the ruby shebang line.
  • require “thor” in your script.
  • define your Thor class.
  • add #{YourThorClassname}.start to the bottom of your script.
例: mythorcommand.rb
Example: mythorcommand.rb
#!/usr/bin/env ruby
require "rubygems" # ruby1.9 doesn't "require" it though
require "thor"

class MyThorCommand < Thor
  desc "foo", "Prints foo"
  def foo
    puts "foo"
  end
end

MyThorCommand.start
スクリプトを実行可能にする:
Make the script executable:
chmod a+x mythorcommand.rb
今このようにタイプして実行できる:
Now you can type:
./mythorcommand.rb foo

0 件のコメント:

コメントを投稿

何かありましたら、どうぞ: