jsierles / thor forked from wycats/thor

A scripting framework that replaces rake and sake

This URL has Read+Write access

thor /
name age message
file .autotest Wed May 07 19:28:50 -0700 2008 First pass of Thor::Runner [wycats]
file .gitignore Thu May 15 18:22:28 -0700 2008 Add coverage to gitignore. [nex3]
file LICENSE Tue May 06 19:21:22 -0700 2008 Initial checkin of Hermes [wycats]
file README.markdown Tue May 13 20:47:15 -0700 2008 Update the Readme to be about Thor, not Hermes. [nex3]
file Rakefile Wed May 14 17:53:45 -0700 2008 Get rid of all Rakefile stuff except install. W... [nex3]
file Thorfile Sat May 17 22:40:06 -0700 2008 Add rake2thor to the gem binfiles. [nex3]
directory bin/ Sun May 18 02:46:46 -0700 2008 Get rid of the ObjectSpace monkeypatch in the t... [nex3]
directory lib/ Loading commit data...
directory script/ Tue May 06 19:21:22 -0700 2008 Initial checkin of Hermes [wycats]
directory spec/
file task.thor Sat May 17 01:06:55 -0700 2008 Make sure opts parameters are always optional. [nex3]
file thor.gemspec Mon May 19 17:42:26 -0700 2008 Update gemspec [wycats]
README.markdown

thor

Map options to a class. Simply create a class with the appropriate annotations, and have options automatically map to functions and parameters.

Examples:

class MyApp < Thor                                                        # [1]
  map "-L" => :list                                                       # [2]

  desc "install APP_NAME", "install one of the available apps"            # [3]
  method_options :force => :boolean                                       # [4]
  def install(name, opts)
    ... code ...
    if opts[:force]
      # do something
    end
  end

  desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
  def list(search = "")
    # list everything
  end

end

MyApp.start

Thor automatically maps commands as follows:

app install name --force

That gets converted to:

MyApp.new.install("name", :force => true)

[1] Inherit from Thor to turn a class into an option mapper

[2] Map additional non-valid identifiers to specific methods. In this case,

convert -L to :list

[3] Describe the method immediately below. The first parameter is the usage information,

and the second parameter is the description.

[4] Provide any additional options. These will be marshaled from -- and - params.

In this case, a --force and a -f option is added.

Types for method_options

:boolean
true if the option is passed
:required
A key/value option that MUST be provided
:optional
A key/value option that MAY be provided