Class: CommandKit::Commands::Help

Inherits:
CommandKit::Command show all
Includes:
ParentCommand
Defined in:
lib/command_kit/commands/help.rb

Overview

The default help command.

Constant Summary

Constants included from Printing

Printing::EOL

Instance Attribute Summary

Attributes included from ParentCommand

#parent_command

Attributes included from CommandKit::CommandName

#command_name

Attributes included from Options

#options

Attributes included from Options::Parser

#option_parser

Attributes included from Env

#env

Instance Method Summary collapse

Methods included from ParentCommand

#initialize

Methods included from FileUtils

#erb

Methods included from ExceptionHandler

#main, #on_exception

Methods included from Printing

#print_error, #print_exception

Methods included from Stdio

#abort, #gets, #initialize, #print, #printf, #putc, #puts, #readline, #readlines, #stderr, #stdin, #stdout

Methods included from Description

#description, #help, #help_description

Methods included from Description::ModuleMethods

#included

Methods included from Help

#help

Methods included from Help::ModuleMethods

#included

Methods included from Examples

#examples, #help, #help_examples

Methods included from Examples::ModuleMethods

#included

Methods included from CommandKit::CommandName

#initialize

Methods included from CommandKit::CommandName::ModuleMethods

#included

Methods included from Options

#help, #initialize

Methods included from Options::ModuleMethods

#included

Methods included from Options::Parser

#help, #help_options, #initialize, #main, #on_ambiguous_argument, #on_ambiguous_option, #on_invalid_argument, #on_invalid_option, #on_missing_argument, #on_needless_argument, #on_parse_error, #parse_options

Methods included from Options::Parser::ModuleMethods

#included

Methods included from Main

#main

Methods included from Main::ModuleMethods

#included

Methods included from Usage

#help, #help_usage, #usage

Methods included from Usage::ModuleMethods

#included

Methods included from Arguments

#help, #help_arguments, #main

Methods included from Arguments::ModuleMethods

#included

Methods included from Env

#initialize

Instance Method Details

#run(command = nil) ⇒ Object

Prints the given commands --help output or lists registered commands.

Parameters:

  • command (String, nil) (defaults to: nil)

    The given command name, or nil if no command name was given.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/command_kit/commands/help.rb', line 26

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