Add --no-color cli flag

closes #72
This commit is contained in:
Vitalii Elenhaupt 2018-08-13 00:04:39 +03:00
parent 248c5a656b
commit d60aea102f
No known key found for this signature in database
GPG Key ID: 7558EF3A4056C706
3 changed files with 18 additions and 2 deletions

View File

@ -57,6 +57,16 @@ module Ameba::Cli
c.formatter.should eq :todo
end
it "accepts --no-color flag" do
c = Cli.parse_args %w(--no-color)
c.colors?.should be_false
end
it "doesn't disable colors by default" do
c = Cli.parse_args %w(--all)
c.colors?.should be_true
end
it "ignores --config if --gen-config flag passed" do
c = Cli.parse_args %w(--gen-config --config my_config.yml)
c.formatter.should eq :todo

View File

@ -7,7 +7,7 @@ module Ameba::Cli
def run(args)
opts = parse_args args
config = Config.load opts.config
config = Config.load opts.config, opts.colors?
config.files = opts.files
configure_formatter(config, opts)
@ -26,6 +26,7 @@ module Ameba::Cli
property only : Array(String)?
property except : Array(String)?
property? all = false
property? colors = true
end
def parse_args(args, opts = Opts.new)
@ -66,6 +67,10 @@ module Ameba::Cli
opts.formatter = :todo
opts.config = ""
end
parser.on("--no-color", "Disable colors") do
opts.colors = false
end
end
opts

View File

@ -46,7 +46,8 @@ class Ameba::Config
# config = Ameba::Config.load
# ```
#
def self.load(path = PATH)
def self.load(path = PATH, colors? = true)
Colorize.enabled = colors?
content = File.exists?(path) ? File.read path : ""
Config.new YAML.parse(content)
rescue e