Class: Abide::CLI::XccdfDiffCommand

Inherits:
AbideCommand
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/xccdf.rb

Constant Summary collapse

CMD_NAME =
'diff'
CMD_SHORT =
'Generates a diff report between two XCCDF files'
CMD_LONG =
'Generates a diff report between two XCCDF files'
CMD_FILE1_ARG =
'path to first XCCDF file'
CMD_FILE2_ARG =
'path to second XCCDF file'

Constants included from AbideDevUtils::Config

AbideDevUtils::Config::DEFAULT_PATH

Instance Method Summary collapse

Methods inherited from AbideCommand

#deprecated?, #on_after_add

Methods included from AbideDevUtils::Config

config_section, #config_section, fetch, #fetch, to_h, #to_h

Constructor Details

#initializeXccdfDiffCommand

Returns a new instance of XccdfDiffCommand.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/abide_dev_utils/cli/xccdf.rb', line 104

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
  argument_desc(FILE1: CMD_FILE1_ARG, FILE2: CMD_FILE2_ARG)
  options.on('-o [PATH]', '--out-file', 'Save the report as a yaml file') { |x| @data[:outfile] = x }
  options.on('-p [PROFILE]', '--profile',
             'Only diff rules belonging to the matching profile. Takes a string that is treated as RegExp') do |x|
    @data[:profile] = x
  end
  options.on('-l [LEVEL]', '--level',
             'Only diff rules belonging to the matching level. Takes a string that is treated as RegExp') do |x|
    @data[:level] = x
  end
  options.on('-i [PROPS]', '--ignore-changed-properties',
             'Ignore changes to specified properties. Takes a comma-separated list.') do |x|
    @data[:ignore_changed_properties] = x.split(',')
  end
  options.on('-r', '--raw', 'Output the diff in raw format') { @data[:raw] = true }
  options.on('-q', '--quiet', 'Show no output in the terminal') { @data[:quiet] = false }
end

Instance Method Details

#execute(file1, file2) ⇒ Object



124
125
126
127
# File 'lib/abide_dev_utils/cli/xccdf.rb', line 124

def execute(file1, file2)
  diffreport = AbideDevUtils::XCCDF.diff(file1, file2, @data)
  AbideDevUtils::Output.yaml(diffreport, console: @data.fetch(:quiet, true), file: @data.fetch(:outfile, nil))
end