Module: DnsMadeEasy::CLI::MessageHelpers

Included in:
Commands::Base
Defined in:
lib/dnsmadeeasy/cli/message_helpers.rb

Overview

Colorful boxed CLI status messages. All boxes print to stderr so that stdout carries only command payload (zone files, plan output) and stays safe to pipe or redirect.

Include the module to call info/success/warning/error directly from a command; boxes then print to the includer's @err stream when present. The module-level methods (MessageHelpers.error etc.) remain available for callers outside the command classes.

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

BOX_OPTIONS =
{
  border: { type: :thick },
  width: 85
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.stderrObject

Returns the value of attribute stderr.



22
23
24
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 22

def stderr
  @stderr
end

.stdoutObject

Returns the value of attribute stdout.



22
23
24
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 22

def stdout
  @stdout
end

Class Method Details

.error(message) ⇒ Object



36
37
38
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 36

def error(message)
  print_box(:error, message, stderr)
end

.included(base) ⇒ Object



24
25
26
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 24

def included(base)
  base.include(InstanceMethods)
end

.info(message) ⇒ Object



28
29
30
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 28

def info(message)
  print_box(:info, message, stderr)
end


44
45
46
47
48
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 44

def print_box(box_type, message, output)
  box = TTY::Box.public_send(box_type, message, **BOX_OPTIONS)
  output.puts(box)
  box
end

.success(message) ⇒ Object



40
41
42
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 40

def success(message)
  print_box(:success, message, stderr)
end

.warn(message) ⇒ Object



32
33
34
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 32

def warn(message)
  print_box(:warn, message, stderr)
end