lib/thor.rb in atli-0.1.7 vs lib/thor.rb in atli-0.1.8

- old
+ new

@@ -1,9 +1,10 @@ require "set" require 'nrser' require 'semantic_logger' require "thor/base" +require 'thor/example' class Thor class << self @@ -196,18 +197,40 @@ handle_no_command_error(meth) unless command shell.say "Usage:" shell.say " #{banner(command, nil, subcommand)}" shell.say - class_options_help(shell, nil => command.options.values) + + class_options_help \ + shell, + command.options.values.group_by { |option| option.group } + if command.long_description shell.say "Description:" shell.print_wrapped(command.long_description, :indent => 2) else shell.say command.description end + unless command.examples.empty? + shell.say "\n" + shell.say "Examples:" + shell.say "\n" + + command.examples.each_with_index do |example, index| + lines = example.lines + + shell.say "1. #{ lines[0] }" + + lines[1..-1].each do |line| + shell.say " #{ line }" + end + end + + shell.say "\n" + end + nil end alias_method :task_help, :command_help # Prints help information for this class. @@ -433,14 +456,30 @@ # Hash mapping option names (as {Symbol}) to instances. # def find_shared_method_options *names, groups: nil groups_set = Set[*groups] - shared_method_options. - select { |name, option| - names.include?( name ) || !(option.groups & groups_set).empty? - } + shared_method_options.each_with_object( {} ) do |(name, option), results| + match = {} + + if names.include? name + match[:name] = true + end + + match_groups = option.groups & groups_set + + unless match_groups.empty? + match[:groups] = match_groups + end + + unless match.empty? + results[name] = { + option: option, + match: match, + } + end + end end alias_method :find_shared_options, :find_shared_method_options # Declare a shared method option with an optional groups that can then @@ -551,12 +590,12 @@ # @param (see .find_shared_method_options) # @return (see .find_shared_method_options) # def include_method_options *names, groups: nil find_shared_method_options( *names, groups: groups ). - each do |name, option| - method_options[name] = option + each do |name, result| + method_options[name] = Thor::IncludedOption.new **result end end alias_method :include_options, :include_method_options @@ -648,19 +687,23 @@ def create_command(meth) #:nodoc: @usage ||= nil @desc ||= nil @long_desc ||= nil @hide ||= nil + + examples = @examples || [] + @examples = [] if @usage && @desc base_class = @hide ? Thor::HiddenCommand : Thor::Command - commands[meth] = base_class.new( - meth, - @desc, - @long_desc, - @usage, - method_options - ) + commands[meth] = base_class.new \ + name: meth, + description: @desc, + long_description: @long_desc, + usage: @usage, + examples: examples, + options: method_options + @usage, @desc, @long_desc, @method_options, @hide = nil true elsif all_commands[meth] || meth == "method_missing" true else