|
31 | 31 | require 'rest_client' |
32 | 32 | require 'securerandom' |
33 | 33 | require_relative 'bom_helpers' |
| 34 | +require 'active_support/core_ext/hash' |
34 | 35 |
|
35 | 36 | class Bombuilder |
| 37 | + SUPPORTED_BOM_FORMATS = %w[xml json] |
| 38 | + |
36 | 39 | def self.build(path) |
37 | 40 | original_working_directory = Dir.pwd |
38 | 41 | setup(path) |
39 | 42 | specs_list |
40 | | - bom = build_bom(@gems) |
| 43 | + bom = build_bom(@gems, @bom_output_format) |
41 | 44 |
|
42 | 45 | begin |
43 | 46 | @logger.info("Changing directory to the original working directory located at #{original_working_directory}") |
@@ -84,6 +87,9 @@ def self.setup(path) |
84 | 87 | opts.on('-o', '--output bom_file_path', '(Optional) Path to output the bom.xml file to') do |bom_file_path| |
85 | 88 | @options[:bom_file_path] = bom_file_path |
86 | 89 | end |
| 90 | + opts.on('-f', '--format bom_output_format', '(Optional) Output format for bom. Currently support xml (default) and json.') do |bom_output_format| |
| 91 | + @options[:bom_output_format] = bom_output_format |
| 92 | + end |
87 | 93 | opts.on_tail('-h', '--help', 'Show help message') do |
88 | 94 | puts opts |
89 | 95 | exit |
@@ -119,8 +125,17 @@ def self.setup(path) |
119 | 125 | abort |
120 | 126 | end |
121 | 127 |
|
| 128 | + if @options[:bom_output_format].nil? |
| 129 | + @bom_output_format = 'xml' |
| 130 | + elsif SUPPORTED_BOM_FORMATS.include?(@options[:bom_output_format]) |
| 131 | + @bom_output_format = @options[:bom_output_format] |
| 132 | + else |
| 133 | + @logger.error("Unrecognized cyclonedx bom output format provided. Please choose one of #{SUPPORTED_BOM_FORMATS}") |
| 134 | + abort |
| 135 | + end |
| 136 | + |
122 | 137 | @bom_file_path = if @options[:bom_file_path].nil? |
123 | | - './bom.xml' |
| 138 | + "./bom.#{@bom_output_format}" |
124 | 139 | else |
125 | 140 | @options[:bom_file_path] |
126 | 141 | end |
|
0 commit comments