-
Notifications
You must be signed in to change notification settings - Fork 553
Making An Executable
coderifous edited this page Apr 22, 2011
·
4 revisions
You may want to make a script as an executable command. To do this with Thor:
- Include the ruby shebang line.
- Require "thor" in your script.
- Define your Thor class.
- Add #{your thor class name}.start to the bottom of your script.
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