github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/steampipeconfig/versionmap/resolved_version_list_map.go (about) 1 package versionmap 2 3 import ( 4 "github.com/turbot/steampipe/pkg/steampipeconfig/modconfig" 5 ) 6 7 // ResolvedVersionListMap represents a map of ResolvedVersionConstraint arrays, keyed by dependency name 8 type ResolvedVersionListMap map[string][]*ResolvedVersionConstraint 9 10 // Add appends the version constraint to the list for the given name 11 func (m ResolvedVersionListMap) Add(name string, versionConstraint *ResolvedVersionConstraint) { 12 // if there is already an entry for the same name, replace it 13 // TODO handle alias 14 m[name] = []*ResolvedVersionConstraint{versionConstraint} 15 } 16 17 // Remove removes the given version constraint from the list for the given name 18 func (m ResolvedVersionListMap) Remove(name string, constraint *ResolvedVersionConstraint) { 19 var res []*ResolvedVersionConstraint 20 for _, c := range m[name] { 21 if !c.Equals(constraint) { 22 res = append(res, c) 23 } 24 } 25 m[name] = res 26 } 27 28 // FlatMap converts the ResolvedVersionListMap map into a map keyed by the FULL dependency name (i.e. including version( 29 func (m ResolvedVersionListMap) FlatMap() map[string]*ResolvedVersionConstraint { 30 var res = make(map[string]*ResolvedVersionConstraint) 31 for name, versions := range m { 32 for _, version := range versions { 33 key := modconfig.BuildModDependencyPath(name, version.Version) 34 res[key] = version 35 } 36 } 37 return res 38 } 39 40 // FlatNames converts the ResolvedVersionListMap map into a string array of full names 41 func (m ResolvedVersionListMap) FlatNames() []string { 42 var res []string 43 for name, versions := range m { 44 for _, version := range versions { 45 res = append(res, modconfig.BuildModDependencyPath(name, version.Version)) 46 } 47 } 48 return res 49 }