Exception: CLAide::Help

Inherits:
StandardError
  • Object
show all
Includes:
InformativeError
Defined in:
lib/claide/help.rb

Overview

The exception class that is raised to indicate a help banner should be shown while running Command.run.

Instance Attribute Summary collapse

Attributes included from InformativeError

#exit_status

Instance Method Summary collapse

Constructor Details

#initialize(banner, error_message = nil) ⇒ Help

Note:

If an error message is provided, the exit status, used to terminate the program with, will be set to 1, otherwise a CLAide::Help exception is treated as not being a real error and exits with 0.

Returns a new instance of Help.

Parameters:

  • banner (String)

    @see banner

  • error_message (String) (defaults to: nil)

    @see error_message



29
30
31
32
33
# File 'lib/claide/help.rb', line 29

def initialize(banner, error_message = nil)
  @banner = banner
  @error_message = error_message
  @exit_status = @error_message.nil? ? 0 : 1
end

Instance Attribute Details

command to show in the help.

Returns:

  • (String)

    The banner containing the usage instructions of the



15
16
17
# File 'lib/claide/help.rb', line 15

def banner
  @banner
end

#error_messageString (readonly)

Returns An optional error message that will be shown before the help banner.

Returns:

  • (String)

    An optional error message that will be shown before the help banner.



20
21
22
# File 'lib/claide/help.rb', line 20

def error_message
  @error_message
end

Instance Method Details

#formatted_error_messageString

Returns The optional error message, colored in red if Command.ansi_output is set to true.

Returns:



38
39
40
41
42
43
# File 'lib/claide/help.rb', line 38

def formatted_error_message
  if error_message
    message = "[!] #{error_message}"
    prettify_error_message(message)
  end
end

#messageString

Returns The optional error message, combined with the help banner of the command.

Returns:

  • (String)

    The optional error message, combined with the help banner of the command.



54
55
56
# File 'lib/claide/help.rb', line 54

def message
  [formatted_error_message, banner].compact.join("\n\n")
end

#prettify_error_message(message) ⇒ String

Returns:



47
48
49
# File 'lib/claide/help.rb', line 47

def prettify_error_message(message)
  message.ansi.red
end