mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 07:26:34 +01:00
add sbom document import lib helper function
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
+11
-2
@@ -19,12 +19,18 @@ type Catalog struct {
|
||||
}
|
||||
|
||||
// NewCatalog returns a new empty Catalog
|
||||
func NewCatalog() *Catalog {
|
||||
return &Catalog{
|
||||
func NewCatalog(pkgs ...Package) *Catalog {
|
||||
catalog := Catalog{
|
||||
byID: make(map[ID]*Package),
|
||||
byType: make(map[Type][]*Package),
|
||||
byFile: make(map[file.Reference][]*Package),
|
||||
}
|
||||
|
||||
for _, p := range pkgs {
|
||||
catalog.Add(p)
|
||||
}
|
||||
|
||||
return &catalog
|
||||
}
|
||||
|
||||
// PackageCount returns the total number of packages that have been added.
|
||||
@@ -111,6 +117,9 @@ func (c *Catalog) Sorted(types ...Type) []*Package {
|
||||
|
||||
sort.SliceStable(pkgs, func(i, j int) bool {
|
||||
if pkgs[i].Name == pkgs[j].Name {
|
||||
if pkgs[i].Version == pkgs[j].Version {
|
||||
return pkgs[i].Type < pkgs[j].Type
|
||||
}
|
||||
return pkgs[i].Version < pkgs[j].Version
|
||||
}
|
||||
return pkgs[i].Name < pkgs[j].Name
|
||||
|
||||
Reference in New Issue
Block a user