module Thor::Base::ClassMethods
def class_options_help(shell, ungrouped_name=nil, extra_group=nil) #:nodoc:
requires two options: the group name and the array of options.
The second is by returning a lambda used to print values. The lambda
extra_group that should be a hash in the format :group => Array[Options].
hooks to add extra options, one of them if the third argument called
any group, it uses the ungrouped name value. This method provide to
Prints the class options per group. If an option does not belong to
def class_options_help(shell, ungrouped_name=nil, extra_group=nil) #:nodoc: groups = {} class_options.each do |_, value| groups[value.group] ||= [] groups[value.group] << value end printer = proc do |group_name, options| list = [] padding = options.collect{ |o| o.aliases.size }.max.to_i * 4 options.each do |option| item = [ option.usage(padding) ] item.push(option.description ? "# #{option.description}" : "") list << item list << [ "", "# Default: #{option.default}" ] if option.show_default? end unless list.empty? shell.say(group_name ? "#{group_name} options:" : "Options:") shell.print_table(list, :ident => 2) shell.say "" end end # Deal with default group global_options = groups.delete(nil) || [] printer.call(ungrouped_name, global_options) if global_options # Print all others groups = extra_group.merge(groups) if extra_group groups.each(&printer) printer end