Shortcuts for help.
Thor methods that should not be overwritten by the user.
Extend check unknown options to accept a hash of conditions.
options
# File lib/thor.rb, line 212 212: def check_unknown_options!(options={}) 213: @check_unknown_options ||= Hash.new 214: options.each do |key, value| 215: if value 216: @check_unknown_options[key] = Array(value) 217: else 218: @check_unknown_options.delete(key) 219: end 220: end 221: @check_unknown_options 222: end
Sets the default task when thor is executed without an explicit task to be called.
meth | name of the defaut task |
# File lib/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
Defines the usage and the description of the next task.
usage
# File lib/thor.rb, line 45 45: def desc(usage, description, options={}) 46: if options[:for] 47: task = find_and_refresh_task(options[:for]) 48: task.usage = usage if usage 49: task.description = description if description 50: else 51: @usage, @desc, @hide = usage, description, options[:hide] || false 52: end 53: end
Prints help information for this class.
shell
# File lib/thor.rb, line 174 174: def help(shell, subcommand = false) 175: list = printable_tasks(true, subcommand) 176: Thor::Util.thor_classes_in(self).each do |klass| 177: list += klass.printable_tasks(false) 178: end 179: list.sort!{ |a,b| a[0] <=> b[0] } 180: 181: shell.say "Tasks:" 182: shell.print_table(list, :ident => 2, :truncate => true) 183: shell.say 184: class_options_help(shell) 185: end
Defines the long description of the next task.
long description
# File lib/thor.rb, line 60 60: def long_desc(long_description, options={}) 61: if options[:for] 62: task = find_and_refresh_task(options[:for]) 63: task.long_description = long_description if long_description 64: else 65: @long_desc = long_description 66: end 67: end
Maps an input to a task. If you define:
map "-T" => "list"
Running:
thor -T
Will invoke the list task.
Hash[String|Array => Symbol] | Maps the string or the strings in the array to the given task. |
# File lib/thor.rb, line 82 82: def map(mappings=nil) 83: @map ||= from_superclass(:map, {}) 84: 85: if mappings 86: mappings.each do |key, value| 87: if key.respond_to?(:each) 88: key.each {|subkey| @map[subkey] = value} 89: else 90: @map[key] = value 91: end 92: end 93: end 94: 95: @map 96: end
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
name | The name of the argument. |
options | Described below. |
: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/thor.rb, line 136 136: def method_option(name, options={}) 137: scope = if options[:for] 138: find_and_refresh_task(options[:for]).options 139: else 140: method_options 141: end 142: 143: build_option(name, options, scope) 144: end
Declares the options for the next task to be declared.
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 105 105: def method_options(options=nil) 106: @method_options ||= {} 107: build_options(options, @method_options) if options 108: @method_options 109: end
Returns tasks ready to be printed.
# File lib/thor.rb, line 188 188: def printable_tasks(all = true, subcommand = false) 189: (all ? all_tasks : tasks).map do |_, task| 190: next if task.hidden? 191: item = [] 192: item << banner(task, false, subcommand) 193: item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "") 194: item 195: end.compact 196: end
Registers another Thor subclass as a command.
klass | Thor subclass to register |
command | Subcommand name to use |
usage | Short usage for the subcommand |
description | Description for the subcommand |
# File lib/thor.rb, line 28 28: def register(klass, subcommand_name, usage, description, options={}) 29: if klass <= Thor::Group 30: desc usage, description, options 31: define_method(subcommand_name) { invoke klass } 32: else 33: desc usage, description, options 34: subcommand subcommand_name, klass 35: end 36: end
# File lib/thor.rb, line 202 202: def subcommand(subcommand, subcommand_class) 203: self.subcommands << subcommand.to_s 204: subcommand_class.subcommand_help subcommand 205: define_method(subcommand) { |*args| invoke subcommand_class, args } 206: end
# File lib/thor.rb, line 198 198: def subcommands 199: @subcommands ||= from_superclass(:subcommands, []) 200: end
Prints help information for the given task.
shell
# File lib/thor.rb, line 152 152: def task_help(shell, task_name) 153: meth = normalize_task_name(task_name) 154: task = all_tasks[meth] 155: handle_no_task_error(meth) unless task 156: 157: shell.say "Usage:" 158: shell.say " #{banner(task)}" 159: shell.say 160: class_options_help(shell, nil => task.options.map { |_, o| o }) 161: if task.long_description 162: shell.say "Description:" 163: shell.print_wrapped(task.long_description, :ident => 2) 164: else 165: shell.say task.description 166: end 167: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.