Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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 d529605
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/kbsecret/cli.rb
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit d529605

Please sign in to comment.