Skip to content

Commit

Permalink
Add --no-color option
Browse files Browse the repository at this point in the history
  • Loading branch information
andxyz committed Jan 7, 2020
1 parent 7ce5567 commit e46d5d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/foreman/cli.rb
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions lib/foreman/engine/cli.rb
Expand Up @@ -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"]
Expand All @@ -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)
Expand Down

0 comments on commit e46d5d5

Please sign in to comment.