Permalink
Browse files

lib/cli: Implement NO_COLOR support

When NO_COLOR is set in the environment, KBSecret will avoid
using TTY colors in its output.
  • Loading branch information...
woodruffw committed Apr 13, 2018
1 parent 3bf9624 commit d5296054d979a1b1ce07c1be78d56d3d29b62384
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/kbsecret/cli.rb
@@ -159,7 +159,8 @@ def guard
# @param msg [String] the message to print
# @return [void]
def info(msg)
self.class.stderr.puts "#{GREEN["Info"]}: #{msg}"
info = ENV["NO_COLOR"] ? "Info" : GREEN["Info"]
self.class.stderr.puts "#{info}: #{msg}"
end
# Print an information message, but only if verbose output has been enabled.
@@ -184,25 +185,26 @@ def bye(msg)
# @return [void]
def warn(msg)
return if @opts.no_warn?
self.class.stderr.puts "#{YELLOW["Warning"]}: #{msg}"
warning = ENV["NO_COLOR"] ? "Warning" : YELLOW["Warning"]
self.class.stderr.puts "#{warning}: #{msg}"
end
# Print an error message and terminate.
# @param msg [String] the message to print
# @return [void]
# @note This method does not return!
def die(msg)
pretty = "#{RED["Fatal"]}: #{msg}"
abort pretty
fatal = ENV["NO_COLOR"] ? "Fatal" : RED["Fatal"]
abort "#{fatal}: #{msg}"
end
# Print an error message and terminate.
# @param msg [String] the message to print
# @return [void]
# @note This method does not return!
def self.die(msg)
pretty = "#{RED["Fatal"]}: #{msg}"
abort pretty
fatal = ENV["NO_COLOR"] ? "Fatal" : RED["Fatal"]
abort "#{fatal}: #{msg}"
end
# Finds a reasonable default field separator by checking the environment first

0 comments on commit d529605

Please sign in to comment.