Parent

Included Modules

Thor

Constants

HELP_MAPPINGS

Shortcuts for help.

THOR_RESERVED_WORDS

Thor methods that should not be overwritten by the user.

VERSION

Public Class Methods

check_unknown_options!(options={}) click to toggle source

Extend check unknown options to accept a hash of conditions.

Parameters

options: A hash containing :only and/or :except keys

     # File lib/bundler/vendor/thor.rb, line 195
195:     def check_unknown_options!(options={})
196:       @check_unknown_options ||= Hash.new
197:       options.each do |key, value|
198:         if value
199:           @check_unknown_options[key] = Array(value)
200:         else
201:           @check_unknown_options.delete(key)
202:         end
203:       end
204:       @check_unknown_options
205:     end
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/bundler/vendor/thor.rb, line 10
10:     def default_task(meth=nil)
11:       case meth
12:         when :none
13:           @default_task = 'help'
14:         when nil
15:           @default_task ||= from_superclass(:default_task, 'help')
16:         else
17:           @default_task = meth.to_s
18:       end
19:     end
desc(usage, description, options={}) click to toggle source

Defines the usage and the description of the next task.

Parameters

usage description options

    # File lib/bundler/vendor/thor.rb, line 28
28:     def desc(usage, description, options={})
29:       if options[:for]
30:         task = find_and_refresh_task(options[:for])
31:         task.usage = usage             if usage
32:         task.description = description if description
33:       else
34:         @usage, @desc, @hide = usage, description, options[:hide] || false
35:       end
36:     end
help(shell, subcommand = false) click to toggle source

Prints help information for this class.

Parameters

shell

     # File lib/bundler/vendor/thor.rb, line 157
157:     def help(shell, subcommand = false)
158:       list = printable_tasks(true, subcommand)
159:       Thor::Util.thor_classes_in(self).each do |klass|
160:         list += klass.printable_tasks(false)
161:       end
162:       list.sort!{ |a,b| a[0] <=> b[0] }
163: 
164:       shell.say "Tasks:"
165:       shell.print_table(list, :ident => 2, :truncate => true)
166:       shell.say
167:       class_options_help(shell)
168:     end
long_desc(long_description, options={}) click to toggle source

Defines the long description of the next task.

Parameters

long description

    # File lib/bundler/vendor/thor.rb, line 43
43:     def long_desc(long_description, options={})
44:       if options[:for]
45:         task = find_and_refresh_task(options[:for])
46:         task.long_description = long_description if long_description
47:       else
48:         @long_desc = long_description
49:       end
50:     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/bundler/vendor/thor.rb, line 65
65:     def map(mappings=nil)
66:       @map ||= from_superclass(:map, {})
67: 
68:       if mappings
69:         mappings.each do |key, value|
70:           if key.respond_to?(:each)
71:             key.each {|subkey| @map[subkey] = value}
72:           else
73:             @map[key] = value
74:           end
75:         end
76:       end
77: 
78:       @map
79:     end
method_option(name, options={}) click to toggle source

Adds an option to the set of method 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_option :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. :banner - String to show on usage notes.

     # File lib/bundler/vendor/thor.rb, line 119
119:     def method_option(name, options={})
120:       scope = if options[:for]
121:         find_and_refresh_task(options[:for]).options
122:       else
123:         method_options
124:       end
125: 
126:       build_option(name, options, scope)
127:     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/bundler/vendor/thor.rb, line 88
88:     def method_options(options=nil)
89:       @method_options ||= {}
90:       build_options(options, @method_options) if options
91:       @method_options
92:     end
printable_tasks(all = true, subcommand = false) click to toggle source

Returns tasks ready to be printed.

     # File lib/bundler/vendor/thor.rb, line 171
171:     def printable_tasks(all = true, subcommand = false)
172:       (all ? all_tasks : tasks).map do |_, task|
173:         next if task.hidden?
174:         item = []
175:         item << banner(task, false, subcommand)
176:         item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
177:         item
178:       end.compact
179:     end
subcommand(subcommand, subcommand_class) click to toggle source
     # File lib/bundler/vendor/thor.rb, line 185
185:     def subcommand(subcommand, subcommand_class)
186:       self.subcommands << subcommand.to_s
187:       subcommand_class.subcommand_help subcommand
188:       define_method(subcommand) { |*args| invoke subcommand_class, args }
189:     end
subcommands() click to toggle source
     # File lib/bundler/vendor/thor.rb, line 181
181:     def subcommands
182:       @subcommands ||= from_superclass(:subcommands, [])
183:     end
task_help(shell, task_name) click to toggle source

Prints help information for the given task.

Parameters

shell task_name

     # File lib/bundler/vendor/thor.rb, line 135
135:     def task_help(shell, task_name)
136:       meth = normalize_task_name(task_name)
137:       task = all_tasks[meth]
138:       handle_no_task_error(meth) unless task
139: 
140:       shell.say "Usage:"
141:       shell.say "  #{banner(task)}"
142:       shell.say
143:       class_options_help(shell, nil => task.options.map { |_, o| o })
144:       if task.long_description
145:         shell.say "Description:"
146:         shell.print_wrapped(task.long_description, :ident => 2)
147:       else
148:         shell.say task.description
149:       end
150:     end

Protected Class Methods

subcommand_help(cmd) click to toggle source
     # File lib/bundler/vendor/thor.rb, line 302
302:       def subcommand_help(cmd)
303:         desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
304:         class_eval           def help(task = nil, subcommand = true); super; end
305:       end

Public Instance Methods

help(task = nil, subcommand = false) click to toggle source
     # File lib/bundler/vendor/thor.rb, line 316
316:   def help(task = nil, subcommand = false)
317:     task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
318:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.