Class: Thor::Shell::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/branch/name/cli/thor_ext/shell/basic/say_error.rb

Instance Method Summary collapse

Instance Method Details

#say_error(message, color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) ⇒ Object

Prints an error message to ‘stderr`.

Parameters:

  • message (String)

    The message to print to ‘stderr`.

  • color (Symbol, nil) (defaults to: nil)

    Optional ANSI color.

  • force_new_line (Boolean) (defaults to: (message.to_s !~ /( |\t)\Z/))

    Controls whether a newline character will be appended to the output.



21
22
23
24
25
26
27
28
29
# File 'lib/branch/name/cli/thor_ext/shell/basic/say_error.rb', line 21

def say_error(message, color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
  return if quiet?

  buffer = prepare_message(message, *color)
  buffer << $INPUT_RECORD_SEPARATOR if force_new_line && !message.to_s.end_with?($INPUT_RECORD_SEPARATOR)

  stderr.print(buffer)
  stderr.flush
end