Sha256: 9a65600aa904e053761ac657c182a729e96186ea1c7d4f430116504057f1b167

Contents?: true

Size: 1019 Bytes

Versions: 3

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

require 'command_kit/command'
require 'command_kit/commands/parent_command'

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

      include ParentCommand

      argument :command, 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 "#{command_name}: unknown command: #{command}"
            exit(1)
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
command_kit-0.1.0.rc1 lib/command_kit/commands/help.rb
command_kit-0.1.0.pre2 lib/command_kit/commands/help.rb
command_kit-0.1.0.pre1 lib/command_kit/commands/help.rb