Path: | README.markdown |
Last Update: | Tue Mar 03 13:32:57 -0700 2009 |
thor
Map options to a class. Simply create a class with the appropriate annotations, and have options automatically map to functions and parameters.
Example:
class MyApp < Thor # [1] map "-L" => :list # [2] desc "install APP_NAME", "install one of the available apps" # [3] method_options :force => :boolean, :alias => :optional # [4] 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
Thor automatically maps commands as such:
app install myname --force
That gets converted to:
MyApp.new.install("myname") # with {'force' => true} as options hash
Types for `method_options`