lib/sifttter_redux/cli_message.rb in sifttter-redux-0.3.5 vs lib/sifttter_redux/cli_message.rb in sifttter-redux-0.3.6
- old
+ new
@@ -3,30 +3,32 @@
module SifttterRedux
# ======================================================
# CliManager Module
# Singleton to manage common CLI interfacing
# ======================================================
- module CliMessage
+ module CLIMessage
# ----------------------------------------------------
# error method
#
# Outputs a formatted-red error message.
# @param m The message to output
# @return Void
# ----------------------------------------------------
- def self.error(m)
+ def self.error(m, log = true)
+ Methadone::CLILogging.error(m) if log
puts "---> ERROR: #{ m }".red
end
# ----------------------------------------------------
# info method
#
# Outputs a formatted-blue informational message.
# @param m The message to output
# @return Void
# ----------------------------------------------------
- def self.info(m)
+ def self.info(m, log = true)
+ Methadone::CLILogging.info(m) if log
puts "---> INFO: #{ m }".blue
end
# ----------------------------------------------------
# info_block method
@@ -35,27 +37,29 @@
# @param m1 The opening message to output
# @param m2 The closing message to output
# @param multiline Whether the message should be multiline
# @return Void
# ----------------------------------------------------
- def self.info_block(m1, m2 = 'Done.', multiline = false)
+ def self.info_block(m1, m2 = 'Done.', multiline = false, log = true)
if block_given?
if multiline
- info(m1)
+ info(m1, log)
else
print "---> INFO: #{ m1 }".blue
end
yield
if multiline
- info(m2)
+ info(m2, log)
else
puts m2.blue
end
else
- fail ArgumentError, 'Did not specify a valid block'
+ error = 'Did not specify a valid block'
+ Methadone::CLILogging.error(error) if log
+ fail ArgumentError, error
end
end
# ----------------------------------------------------
# prompt method
@@ -81,11 +85,12 @@
#
# Outputs a formatted-orange section message.
# @param m The message to output
# @return Void
# ----------------------------------------------------
- def self.section(m)
+ def self.section(m, log = true)
+ Methadone::CLILogging.info(m) if log
puts "#### #{ m }".purple
end
# ----------------------------------------------------
# section_block method
@@ -95,42 +100,46 @@
# @param m1 The opening message to output
# @param m2 The closing message to output
# @param multiline A multiline message or not
# @return Void
# ----------------------------------------------------
- def self.section_block(m, multiline = true)
+ def self.section_block(m, multiline = true, log = true)
if block_given?
if multiline
- section(m)
+ section(m, log)
else
print "#### #{ m }".purple
end
yield
else
- fail ArgumentError, 'Did not specify a valid block'
+ error = 'Did not specify a valid block'
+ Methadone::CLILogging.error(error) if log
+ fail ArgumentError, error
end
end
# ----------------------------------------------------
# success method
#
# Outputs a formatted-green success message.
# @param m The message to output
# @return Void
# ----------------------------------------------------
- def self.success(m)
+ def self.success(m, log = true)
+ Methadone::CLILogging.info(m) if log
puts "---> SUCCESS: #{ m }".green
end
# ----------------------------------------------------
# warning method
#
# Outputs a formatted-yellow warning message.
# @param m The message to output
# @return Void
# ----------------------------------------------------
- def self.warning(m)
+ def self.warning(m, log = true)
+ Methadone::CLILogging.warn(m) if log
puts "---> WARNING: #{ m }".yellow
end
end
end