Module: CommandKit::Printing

Includes:
Stdio
Included in:
Arguments, BugReport, Command, Completion::Install, ExceptionHandler, Open, Options::Parser
Defined in:
lib/command_kit/printing.rb,
lib/command_kit/printing/lists.rb,
lib/command_kit/printing/fields.rb,
lib/command_kit/printing/indent.rb,
lib/command_kit/printing/tables.rb,
lib/command_kit/printing/tables/style.rb,
lib/command_kit/printing/tables/row_builder.rb,
lib/command_kit/printing/tables/border_style.rb,
lib/command_kit/printing/tables/cell_builder.rb,
lib/command_kit/printing/tables/table_builder.rb,
lib/command_kit/printing/tables/table_formatter.rb

Overview

Provides printing methods.

Defined Under Namespace

Modules: Fields, Indent, Lists, Tables

Constant Summary collapse

EOL =

Platform independent new-line constant

Returns:

  • (String)
$/

Instance Method Summary collapse

Methods included from Stdio

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

Instance Method Details

Prints the error message to stderr.

Examples:

print_error "error: invalid input"
# error: invalid input

When CommandKit::CommandName is included:

print_error "invalid input"
# foo: invalid input

Parameters:

  • message (String)

    The error message.



35
36
37
38
39
40
41
42
43
# File 'lib/command_kit/printing.rb', line 35

def print_error(message)
  if respond_to?(:command_name)
    # if #command_name is available, prefix all error messages with it
    stderr.puts "#{command_name}: #{message}"
  else
    # if #command_name is not available, just print the error message as-is
    stderr.puts message
  end
end

Prints an exception to stderr.

Examples:

begin
  # ...
rescue => error
  print_error "Error encountered"
  print_exception(error)
  exit(1)
end

Parameters:

  • error (Exception)

    The error to print.



62
63
64
# File 'lib/command_kit/printing.rb', line 62

def print_exception(error)
  print_error error.full_message(highlight: stderr.tty?)
end