Sha256: 1739c6c471cd6ed6e73eb629efa9fa49c854cfc7b91392239ea7e6e60fc34201

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_relative '../command'
require_relative 'parent_command'

module CommandKit
  module Commands
    #
    # The default help command.
    #
    # @api semipublic
    #
    class Help < Command

      include ParentCommand

      argument :command, required: false,
                         desc: 'Command name to lookup'

      #
      # Prints the given commands `--help` output or lists registered commands.
      #
      # @param [String, nil] command
      #   The given command name, or `nil` if no command name was given.
      #
      def run(command=nil)
        case command
        when nil
          parent_command.help
        else
          if (subcommand = parent_command.command(command))
            unless subcommand.respond_to?(:help)
              raise(TypeError,"#{subcommand.inspect} must define a #help method")
            end

            subcommand.help
          else
            print_error "unknown command: #{command}"
            exit(1)
          end
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
command_kit-0.6.0 lib/command_kit/commands/help.rb
command_kit-0.5.6 lib/command_kit/commands/help.rb
command_kit-0.5.5 lib/command_kit/commands/help.rb
command_kit-0.5.4 lib/command_kit/commands/help.rb
command_kit-0.5.3 lib/command_kit/commands/help.rb
command_kit-0.5.2 lib/command_kit/commands/help.rb
command_kit-0.5.1 lib/command_kit/commands/help.rb