Sha256: 82610d446d57736b3c2d3a8c81fee3edcf5c666133754ace90176a72404d9178

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'command_kit/command'
require 'command_kit/commands/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

6 entries across 6 versions & 1 rubygems

Version Path
command_kit-0.5.0 lib/command_kit/commands/help.rb
command_kit-0.4.1 lib/command_kit/commands/help.rb
command_kit-0.4.0 lib/command_kit/commands/help.rb
command_kit-0.3.0 lib/command_kit/commands/help.rb
command_kit-0.2.2 lib/command_kit/commands/help.rb
command_kit-0.2.1 lib/command_kit/commands/help.rb