What is Thor, and how do I use it?

It provides a clear structure for processing command line arguments,

Thor is like rake on steroids, with support for command line arguments, lack of a DSL in favor of plain old classes (class Spoons < Thor), system wide tasks (like sake), and support for remote tasks.

Yehuda Katz, Thor's author, has a great writeup on the hows and why of Thor.

Building your own thor tasks

# module: random
 
class Amazing < Thor
  desc "describe NAME", "say that someone is amazing"
  method_options :forcefully => :boolean
  def describe(name)
    ret = "#{name} is amazing"
    puts options["forcefully"] ? ret.upcase : ret
  end
 
  desc "hello", "say hello"
  def hello
    puts "Hello"
  end
end

Running your tasks

$ thor amazing:hello

Managing thor tasks

Installing

$ thor install task.thor

will install task.thor Thor file. You can also install thor tasks from a url:

$ thor install http://merbivore.com/merb.thor

In both cases, Thor will prompt you before installing the tasks.

You can also have thor alias the task:

$ thor install task.thor --as my_awesome_task

Updating

You can update installed tasks really easily:

$ thor update my_awesome_task

and Thor will remember where you got the task from, and redownload it.

Listing

You can get a list of all installed thor tasks on your system with:

$ thor installed
 
faqs/thor.txt · Last modified: 2008/12/16 20:37 by 89.239.212.192