From e46d5d57c4e37c1d10e91f48ba07895973fea629 Mon Sep 17 00:00:00 2001 From: Andrew Stevens Date: Tue, 7 Jan 2020 15:20:46 -0500 Subject: [PATCH] Add --no-color option --- lib/foreman/cli.rb | 13 +++++++------ lib/foreman/engine/cli.rb | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 67d697ab..ad9dd310 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -19,12 +19,13 @@ class Foreman::CLI < Foreman::Thor desc "start [PROCESS]", "Start the application (or a specific PROCESS)" - method_option :color, :type => :boolean, :aliases => "-c", :desc => "Force color to be enabled" - method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env" - method_option :formation, :type => :string, :aliases => "-m", :banner => '"alpha=5,bar=3"', :desc => 'Specify what processes will run and how many. Default: "all=1"' - method_option :port, :type => :numeric, :aliases => "-p" - method_option :timeout, :type => :numeric, :aliases => "-t", :desc => "Specify the amount of time (in seconds) processes have to shutdown gracefully before receiving a SIGKILL, defaults to 5." - method_option :timestamp, :type => :boolean, :default => true, :desc => "Include timestamp in output" + method_option :color, :type => :boolean, :aliases => "-c", :desc => "Force color to be enabled" + method_option :"no-color", :type => :boolean, :default => false, :desc => "Force color to be disabled" + method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env" + method_option :formation, :type => :string, :aliases => "-m", :banner => '"alpha=5,bar=3"', :desc => 'Specify what processes will run and how many. Default: "all=1"' + method_option :port, :type => :numeric, :aliases => "-p" + method_option :timeout, :type => :numeric, :aliases => "-t", :desc => "Specify the amount of time (in seconds) processes have to shutdown gracefully before receiving a SIGKILL, defaults to 5." + method_option :timestamp, :type => :boolean, :default => true, :desc => "Include timestamp in output" class << self # Hackery. Take the run method away from Thor so that we can redefine it. diff --git a/lib/foreman/engine/cli.rb b/lib/foreman/engine/cli.rb index 7ea71375..19add82e 100644 --- a/lib/foreman/engine/cli.rb +++ b/lib/foreman/engine/cli.rb @@ -24,13 +24,15 @@ module Color :bright_white => 37, } - def self.enable(io, force=false) + def self.enable(io, force=false, no_color=false) io.extend(self) @@color_force = force + @@no_color = no_color end def color? return true if @@color_force + return false if @@no_color return false if Foreman.windows? return false unless self.respond_to?(:isatty) self.isatty && ENV["TERM"] @@ -50,7 +52,7 @@ def color(name) def startup @colors = map_colors proctitle "foreman: master" unless Foreman.windows? - Color.enable($stdout, options[:color]) + Color.enable($stdout, options[:color], options[:"no-color"]) end def output(name, data)