This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 52b4759a8e21c95a3f432efc8460c86be198ac7a
tree 2b5e5e8ac47b43d90fbc6ace4e07bd5031862a2c
parent 867e912ad9da417e273615e69b1c97b66e210748
tree 2b5e5e8ac47b43d90fbc6ace4e07bd5031862a2c
parent 867e912ad9da417e273615e69b1c97b66e210748
thor /
| name | age | message | |
|---|---|---|---|
| |
.autotest | Wed May 07 19:28:50 -0700 2008 | |
| |
.gitignore | Thu May 15 18:22:28 -0700 2008 | |
| |
CHANGELOG.rdoc | Fri Oct 24 01:08:54 -0700 2008 | |
| |
LICENSE | Tue May 06 19:21:22 -0700 2008 | |
| |
README.markdown | Sun Jan 11 19:57:13 -0800 2009 | |
| |
Rakefile | Fri Aug 15 06:56:57 -0700 2008 | |
| |
Thorfile | Mon Dec 15 12:03:22 -0800 2008 | |
| |
bin/ | ||
| |
lib/ | ||
| |
script/ | Tue May 06 19:21:22 -0700 2008 | |
| |
spec/ | ||
| |
task.thor | Wed Aug 27 07:28:58 -0700 2008 | |
| |
thor.gemspec | Fri Oct 24 01:08:54 -0700 2008 |
README.markdownTypes for
true if the option is passed
same as
the value for this option MUST be provided
the value for this option MAY be provided
the value MAY be provided, but MUST be in numeric form
a String or Numeric
same as
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
- 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--forceand a-foption is added.
Types for method_options
:booleantrue or false:boolean, but fall back to given boolean as default value:required:optional:numeric:optional, but fall back to the given object as default valueIn case of unsatisfied requirements, Thor::Options::Error is raised.
Examples of option parsing:
# let's say this is how we defined options for a method:
method_options(:force => :boolean, :retries => :numeric)
# here is how the following command-line invocations would be parsed:
command -f --retries 5 # => {'force' => true, 'retries' => 5}
command --force -r=5 # => {'force' => true, 'retries' => 5}
command -fr 5 # => {'force' => true, 'retries' => 5}
command --retries=5 # => {'retries' => 5}
command -r5 # => {'retries' => 5}








