Parent

Included Modules

Thor

Constants

HELP_MAPPINGS

Shortcuts for help.

THOR_RESERVED_WORDS

Thor methods that should not be overwritten by the user.

Public Class Methods

default_task(meth=nil) click to toggle source

Sets the default task when thor is executed without an explicit task to be called.

Parameters

meth:name of the defaut task
    # File lib/thor.rb, line 13
13:     def default_task(meth=nil)
14:       case meth
15:         when :none
16:           @default_task = 'help'
17:         when nil
18:           @default_task ||= from_superclass(:default_task, 'help')
19:         else
20:           @default_task = meth.to_s
21:       end
22:     end
desc(usage, description, options={}) click to toggle source

Defines the usage and the description of the next task.

Parameters

usage description

    # File lib/thor.rb, line 30
30:     def desc(usage, description, options={})
31:       if options[:for]
32:         task = find_and_refresh_task(options[:for])
33:         task.usage = usage             if usage
34:         task.description = description if description
35:       else
36:         @usage, @desc = usage, description
37:       end
38:     end
help(shell, meth=nil, options={}) click to toggle source

Prints help information. If a task name is given, it shows information only about the specific task.

Parameters

meth:An optional task name to print usage information about.

Options

namespace:When true, shows the namespace in the output before the usage.
skip_inherited:When true, does not show tasks from superclass.
     # File lib/thor.rb, line 154
154:     def help(shell, meth=nil, options={})
155:       meth, options = nil, meth if meth.is_a?(Hash)
156: 
157:       if meth
158:         task = all_tasks[meth]
159:         raise UndefinedTaskError, "task '#{meth}' could not be found in namespace '#{self.namespace}'" unless task
160: 
161:         shell.say "Usage:"
162:         shell.say "  #{banner(task, options[:namespace], false)}"
163:         shell.say
164:         class_options_help(shell, "Class", :Method => task.options.map { |_, o| o })
165:         shell.say task.description
166:       else
167:         list = (options[:short] ? tasks : all_tasks).map do |_, task|
168:           item = [ banner(task, options[:namespace]) ]
169:           item << "# #{task.short_description}" if task.short_description
170:           item << " "
171:         end
172: 
173:         options[:ident] ||= 2
174:         if options[:short]
175:           shell.print_list(list, :ident => options[:ident])
176:         else
177:           shell.say "Tasks:"
178:           shell.print_list(list, :ident => options[:ident])
179:         end
180: 
181:         Thor::Util.thor_classes_in(self).each do |subclass|
182:           namespace = options[:namespace] == true || subclass.namespace.gsub(/^#{self.namespace}:/, '')
183:           subclass.help(shell, options.merge(:short => true, :namespace => namespace))
184:         end
185: 
186:         class_options_help(shell, "Class") unless options[:short]
187:       end
188:     end
map(mappings=nil) click to toggle source

Maps an input to a task. If you define:

  map "-T" => "list"

Running:

  thor -T

Will invoke the list task.

Parameters

Hash[String|Array => Symbol]:Maps the string or the strings in the array to the given task.
    # File lib/thor.rb, line 53
53:     def map(mappings=nil)
54:       @map ||= from_superclass(:map, {})
55: 
56:       if mappings
57:         mappings.each do |key, value|
58:           if key.respond_to?(:each)
59:             key.each {|subkey| @map[subkey] = value}
60:           else
61:             @map[key] = value
62:           end
63:         end
64:       end
65: 
66:       @map
67:     end
method_option(name, options={}) click to toggle source

Adds an option to the set of class options. If :for is given as option, it allows you to change the options from a previous defined task.

  def previous_task
    # magic
  end

  method_options :foo => :bar, :for => :previous_task

  def next_task
    # magic
  end

Parameters

name:The name of the argument.
options:Described below.

Options

:desc - Description for the argument. :required - If the argument is required or not. :default - Default value for this argument. It cannot be required and have default values. :aliases - Aliases for this option. :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean. :group - The group for this options. Use by class options to output options in different levels. :banner - String to show on usage notes.

     # File lib/thor.rb, line 108
108:     def method_option(name, options={})
109:       scope = if options[:for]
110:         find_and_refresh_task(options[:for]).options
111:       else
112:         method_options
113:       end
114: 
115:       build_option(name, options, scope)
116:     end
method_options(options=nil) click to toggle source

Declares the options for the next task to be declared.

Parameters

Hash[Symbol => Object]:The hash key is the name of the option and the value

is the type of the option. Can be :string, :array, :hash, :boolean, :numeric or :required (string). If you give a value, the type of the value is used.

    # File lib/thor.rb, line 76
76:     def method_options(options=nil)
77:       @method_options ||= {}
78:       build_options(options, @method_options) if options
79:       @method_options
80:     end
start(given_args=ARGV, config={}) click to toggle source

Parses the task and options from the given args, instantiate the class and invoke the task. This method is used when the arguments must be parsed from an array. If you are inside Ruby and want to use a Thor class, you can simply initialize it:

  script = MyScript.new(args, options, config)
  script.invoke(:task, first_arg, second_arg, third_arg)
     # File lib/thor.rb, line 126
126:     def start(given_args=ARGV, config={})
127:       super do
128:         meth = normalize_task_name(given_args.shift)
129:         task = all_tasks[meth]
130: 
131:         if task
132:           args, opts = Thor::Options.split(given_args)
133:           config.merge!(:task_options => task.options)
134:         else
135:           args, opts = given_args, {}
136:         end
137: 
138:         task ||= Thor::Task::Dynamic.new(meth)
139:         trailing = args[Range.new(arguments.size, -1)]
140:         new(args, opts, config).invoke(task, trailing || [])
141:       end
142:     end

Protected Class Methods

Public Instance Methods

help(task=nil) click to toggle source

(Not documented)

     # File lib/thor.rb, line 240
240:   def help(task=nil)
241:     self.class.help(shell, task, :namespace => task && task.include?(?:))
242:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.