lib/bundler/vendor/thor/lib/thor.rb in bundler-1.15.3 vs lib/bundler/vendor/thor/lib/thor.rb in bundler-1.15.4

- old
+ new

@@ -156,14 +156,10 @@ build_option(name, options, scope) end alias_method :option, :method_option - def disable_class_options - @disable_class_options = true - end - # Prints help information for the given command. # # ==== Parameters # shell<Bundler::Thor::Shell> # command_name<String> @@ -239,10 +235,13 @@ args, opts = Bundler::Thor::Arguments.split(args) invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}] invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h") invoke subcommand_class, *invoke_args end + subcommand_class.commands.each do |_meth, command| + command.ancestor_name = subcommand + end end alias_method :subtask, :subcommand # Extend check unknown options to accept a hash of conditions. # @@ -324,16 +323,35 @@ def stop_on_unknown_option?(command) #:nodoc: command && stop_on_unknown_option.include?(command.name.to_sym) end + # Disable the check for required options for the given commands. + # This is useful if you have a command that does not need the required options + # to work, like help. + # + # ==== Parameters + # Symbol ...:: A list of commands that should be affected. + def disable_required_check!(*command_names) + disable_required_check.merge(command_names) + end + + def disable_required_check?(command) #:nodoc: + command && disable_required_check.include?(command.name.to_sym) + end + protected def stop_on_unknown_option #:nodoc: @stop_on_unknown_option ||= Set.new end + # help command has the required check disabled by default. + def disable_required_check #:nodoc: + @disable_required_check ||= Set.new([:help]) + end + # The method responsible for dispatching given the args. def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength meth ||= retrieve_command_name(given_args) command = all_commands[normalize_command_name(meth)] @@ -388,16 +406,16 @@ def create_command(meth) #:nodoc: @usage ||= nil @desc ||= nil @long_desc ||= nil - @disable_class_options ||= nil + @hide ||= nil if @usage && @desc base_class = @hide ? Bundler::Thor::HiddenCommand : Bundler::Thor::Command - commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options, @disable_class_options) - @usage, @desc, @long_desc, @method_options, @hide, @disable_class_options = nil + commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options) + @usage, @desc, @long_desc, @method_options, @hide = nil true elsif all_commands[meth] || meth == "method_missing" true else puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " \ @@ -475,10 +493,9 @@ include Bundler::Thor::Base map HELP_MAPPINGS => :help desc "help [COMMAND]", "Describe available commands or one specific command" - disable_class_options def help(command = nil, subcommand = false) if command if self.class.subcommands.include? command self.class.subcommand_classes[command].help(shell, true) else