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
-
.stderr ⇒ Object
Returns the value of attribute stderr.
-
.stdout ⇒ Object
Returns the value of attribute stdout.
Class Method Summary collapse
- .error(message) ⇒ Object
- .included(base) ⇒ Object
- .info(message) ⇒ Object
- .kv(key, value) ⇒ Object
- .print_box(box_type, message, output) ⇒ Object
- .success(message) ⇒ Object
- .warn(message) ⇒ Object
Class Attribute Details
.stderr ⇒ Object
Returns the value of attribute stderr.
25 26 27 |
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 25 def stderr @stderr end |
.stdout ⇒ Object
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() print_box(:error, , 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() print_box(:info, , 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 |
.print_box(box_type, message, output) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 47 def print_box(box_type, , output) box = TTY::Box.public_send(box_type, , **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() print_box(:success, , stderr) end |
.warn(message) ⇒ Object
35 36 37 |
# File 'lib/dnsmadeeasy/cli/message_helpers.rb', line 35 def warn() print_box(:warn, , stderr) end |