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
KEY_WIDTH =

Right-aligned key column for "key: value" lines inside boxes.

30

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.stderrObject

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

.stdoutObject

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Class Method Details

.error(message) ⇒ Object



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

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

.included(base) ⇒ Object



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

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

.info(message) ⇒ Object



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

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

.kv(key, value) ⇒ Object



54
55
56
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 54

def kv(key, value)
  format("%#{KEY_WIDTH}s: %s", key, value)
end


47
48
49
50
51
52
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 47

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

.success(message) ⇒ Object



43
44
45
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 43

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

.warn(message) ⇒ Object



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

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