Map options to a class. Simply create a class with the appropriate annotations, and have options automatically map to functions and parameters.
class MyApp < Thor #  map "-L" => :list #  desc "install APP_NAME", "install one of the available apps" #  method_options :force => :boolean #  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)
- Inherit from Thor to turn a class into an option mapper
- Map additional non-valid identifiers to specific methods. In this case, convert -L to :list
- Describe the method immediately below. The first parameter is the usage information, and the second parameter is the description.
- Provide any additional options. These will be marshaled from -- and - params. In this case, a --force and a -f option is added.
- true if the option is passed
- the value for this option MUST be provided
- the value for this option MAY be provided
- a String
- same as
:optional; fall back to the given string as default value