mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Implement silencing deprecations
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
6a59618d2b
commit
c5e347bae5
2 changed files with 24 additions and 0 deletions
|
@ -155,6 +155,9 @@ module Inspec
|
|||
desc: "Show progress while executing tests."
|
||||
option :distinct_exit, type: :boolean, default: true,
|
||||
desc: "Exit with code 101 if any tests fail, and 100 if any are skipped (default). If disabled, exit 0 on skips and 1 for failures."
|
||||
option :silence_deprecations, type: :array,
|
||||
banner: "[all]|[GROUP GROUP...]",
|
||||
desc: "Suppress deprecation warnings. See install_dir/etc/deprecations.json for list of GROUPs or use 'all'."
|
||||
end
|
||||
|
||||
def self.format_platform_info(params: {}, indent: 0, color: 39)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require "stringio"
|
||||
require "json"
|
||||
require "inspec/globals"
|
||||
require "inspec/config"
|
||||
|
||||
module Inspec
|
||||
module Deprecation
|
||||
|
@ -32,6 +33,7 @@ module Inspec
|
|||
@groups = {}
|
||||
@unknown_group_action = :warn
|
||||
validate!
|
||||
silence_deprecations_from_cli
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -45,6 +47,25 @@ module Inspec
|
|||
File.open(default_path)
|
||||
end
|
||||
|
||||
def silence_deprecations_from_cli
|
||||
# Read --silence-deprecations CLI option
|
||||
cfg = Inspec::Config.cached
|
||||
return unless cfg[:silence_deprecations]
|
||||
|
||||
groups_to_silence = cfg[:silence_deprecations]
|
||||
silence_all = groups_to_silence.include?("all")
|
||||
|
||||
groups.each do |group_name, group|
|
||||
# Only silence things that warn. Don't silence things that exit;
|
||||
# those harsher measures are usually protecting removed code and ignoring
|
||||
# and continuing regardless would be perilous and lead to errors.
|
||||
if %i{warn fail_control}.include?(group.action) &&
|
||||
(silence_all || groups_to_silence.include?(group_name.to_s))
|
||||
group.action = :ignore
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#====================================================================================================#
|
||||
# Validation
|
||||
#====================================================================================================#
|
||||
|
|
Loading…
Reference in a new issue