Class: Abide::CLI::XccdfGenMapCommand
- Inherits:
-
AbideCommand
- Object
- CmdParse::Command
- AbideCommand
- Abide::CLI::XccdfGenMapCommand
- Defined in:
- lib/abide_dev_utils/cli/xccdf.rb
Constant Summary collapse
- CMD_NAME =
'gen-map'
- CMD_SHORT =
'Generates mappings from XCCDF files'
- CMD_LONG =
'Generates mappings for SCE modules from 1 or more XCCDF files as YAML'
- CMD_XCCDF_FILES_ARG =
'One or more paths to XCCDF files'
Constants included from AbideDevUtils::Config
AbideDevUtils::Config::DEFAULT_PATH
Instance Method Summary collapse
- #execute(*xccdf_files) ⇒ Object
-
#initialize ⇒ XccdfGenMapCommand
constructor
A new instance of XccdfGenMapCommand.
Methods inherited from AbideCommand
Methods included from AbideDevUtils::Config
config_section, #config_section, fetch, #fetch, #to_h, to_h
Constructor Details
#initialize ⇒ XccdfGenMapCommand
Returns a new instance of XccdfGenMapCommand.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/abide_dev_utils/cli/xccdf.rb', line 28 def initialize super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false) argument_desc(XCCDF_FILES: CMD_XCCDF_FILES_ARG) .on('-b [TYPE]', '--benchmark-type [TYPE]', 'XCCDF Benchmark type CIS by default') do |b| @data[:type] = b end .on('-d [DIR]', '--files-output-directory [DIR]', 'Directory to save files data/mappings by default') do |d| @data[:dir] = d end .on('-V', '--version-output-dir', 'If saving to a directory, version the output directory') do @data[:version_output_dir] = true end .on('-q', '--quiet', 'Show no output in the terminal') { @data[:quiet] = true } .on('-p [PREFIX]', '--parent-key-prefix [PREFIX]', 'A prefix to append to the parent key') do |p| @data[:parent_key_prefix] = p end end |
Instance Method Details
#execute(*xccdf_files) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/abide_dev_utils/cli/xccdf.rb', line 47 def execute(*xccdf_files) if @data[:quiet] && @data[:dir].nil? AbideDevUtils::Output.simple("I don\'t know how to quietly output to the console\n¯\\_(ツ)_/¯") exit 1 end xccdf_files.each do |xccdf_file| other_kwarg_syms = %i[type dir quiet parent_key_prefix] other_kwargs = @data.reject { |k, _| other_kwarg_syms.include?(k) } hfile = AbideDevUtils::XCCDF.gen_map( File.(xccdf_file), dir: @data[:dir], type: @data.fetch(:type, 'cis'), parent_key_prefix: @data.fetch(:parent_key_prefix, ''), **other_kwargs ) mapping_dir = File.dirname(hfile.keys[0]) unless @data[:dir].nil? unless @data[:quiet] || @data[:dir].nil? || File.directory?(mapping_dir) AbideDevUtils::Output.simple("Creating directory #{mapping_dir}") end FileUtils.mkdir_p(mapping_dir) unless @data[:dir].nil? hfile.each do |key, val| file_path = @data[:dir].nil? ? nil : key AbideDevUtils::Output.yaml(val, console: @data[:dir].nil?, file: file_path) end end end |