Skip to content

Commit eb8ba79

Browse files
committed
Add vex.MergeFiles()
This adds a new function MergeFiles() which reads a number of paths into vex documents and merges them, returning a new, combined document. Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
1 parent ba89ef1 commit eb8ba79

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pkg/vex/functions_files.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,27 @@ func OpenCSAF(path string, products []string) (*VEX, error) {
217217

218218
return v, nil
219219
}
220+
221+
// MergeFilesWithOptions opens a list of vex documents and after parsing them
222+
// merges them into a single file using the specified merge options.
223+
func MergeFilesWithOptions(mergeOpts *MergeOptions, filePaths []string) (*VEX, error) {
224+
vexDocs := []*VEX{}
225+
for i := range filePaths {
226+
doc, err := Open(filePaths[i])
227+
if err != nil {
228+
return nil, fmt.Errorf("opening %s: %w", filePaths[i], err)
229+
}
230+
vexDocs = append(vexDocs, doc)
231+
}
232+
doc, err := MergeDocumentsWithOptions(mergeOpts, vexDocs)
233+
if err != nil {
234+
return nil, fmt.Errorf("merging opened files: %w", err)
235+
}
236+
return doc, nil
237+
}
238+
239+
// MergeFiles is a convenience wrapper around MergeFilesWithOptions that
240+
// does not take options but performs the merge using the default options
241+
func MergeFiles(filePaths []string) (*VEX, error) {
242+
return MergeFilesWithOptions(&MergeOptions{}, filePaths)
243+
}

0 commit comments

Comments
 (0)