mirror of
https://github.com/inspec/inspec
synced 2024-09-20 22:41:55 +00:00
Merge pull request #5530 from inspec/nm/detect-no-color
Bugfix for `inspec detect --no-color` to not return colourful output
This commit is contained in:
commit
ceeb6c7d3d
3 changed files with 21 additions and 3 deletions
|
@ -181,7 +181,7 @@ module Inspec
|
||||||
puts " Patents: chef.io/patents\n\n"
|
puts " Patents: chef.io/patents\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.format_platform_info(params: {}, indent: 0, color: 39)
|
def self.format_platform_info(params: {}, indent: 0, color: 39, enable_color: true)
|
||||||
str = ""
|
str = ""
|
||||||
params.each do |item, info|
|
params.each do |item, info|
|
||||||
data = info
|
data = info
|
||||||
|
@ -192,7 +192,7 @@ module Inspec
|
||||||
# Do not output fields of data is missing ('unknown' is fine)
|
# Do not output fields of data is missing ('unknown' is fine)
|
||||||
next if data.nil?
|
next if data.nil?
|
||||||
|
|
||||||
data = "\e[1m\e[#{color}m#{data}\e[0m"
|
data = "\e[1m\e[#{color}m#{data}\e[0m" if enable_color
|
||||||
str << format("#{" " * indent}%-10s %s\n", item.to_s.capitalize + ":", data)
|
str << format("#{" " * indent}%-10s %s\n", item.to_s.capitalize + ":", data)
|
||||||
end
|
end
|
||||||
str
|
str
|
||||||
|
|
|
@ -305,7 +305,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
||||||
puts res.to_json
|
puts res.to_json
|
||||||
else
|
else
|
||||||
ui.headline("Platform Details")
|
ui.headline("Platform Details")
|
||||||
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: 36)
|
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: 36, enable_color: ui.color?)
|
||||||
end
|
end
|
||||||
rescue ArgumentError, RuntimeError, Train::UserError => e
|
rescue ArgumentError, RuntimeError, Train::UserError => e
|
||||||
$stderr.puts e.message
|
$stderr.puts e.message
|
||||||
|
|
|
@ -100,6 +100,15 @@ describe "InSpec UI behavior" do
|
||||||
assert_exit_code 0, run_result
|
assert_exit_code 0, run_result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "detect command" do
|
||||||
|
let(:result) { inspec("detect") }
|
||||||
|
|
||||||
|
it "has a colorful output" do
|
||||||
|
_(result.stdout).must_include("\e[")
|
||||||
|
assert_exit_code 0, result
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with --no-color option" do
|
describe "with --no-color option" do
|
||||||
|
@ -130,6 +139,15 @@ describe "InSpec UI behavior" do
|
||||||
assert_exit_code 0, run_result
|
assert_exit_code 0, run_result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "detect command" do
|
||||||
|
let(:result) { inspec("detect --no-color") }
|
||||||
|
|
||||||
|
it "has no color in the output" do
|
||||||
|
_(result.stdout).wont_include("\e[")
|
||||||
|
assert_exit_code 0, result
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "exit codes" do
|
describe "exit codes" do
|
||||||
|
|
Loading…
Reference in a new issue