mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Show optionally dependant packages in readable info
This commit is contained in:
@@ -300,6 +300,35 @@ func (entry *BPMDatabaseEntry) GetEntryDependants() (dependants []string) {
|
||||
return dependants
|
||||
}
|
||||
|
||||
func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string) {
|
||||
dependantsMap := make(map[string][]string)
|
||||
for _, db := range BPMDatabases {
|
||||
for _, e := range db.Entries {
|
||||
if slices.Contains(e.Info.OptionalDepends, entry.Info.Name) {
|
||||
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], e.Database.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get keys
|
||||
keySlice := slices.Collect(maps.Keys(dependantsMap))
|
||||
slices.Sort(keySlice)
|
||||
|
||||
// Add all dependant entries to slice in alphabetical order
|
||||
for _, entryName := range keySlice {
|
||||
dbs := dependantsMap[entryName]
|
||||
if len(dbs) > 1 {
|
||||
for _, db := range dbs {
|
||||
dependants = append(dependants, db+"/"+entryName)
|
||||
}
|
||||
} else {
|
||||
dependants = append(dependants, entryName)
|
||||
}
|
||||
}
|
||||
|
||||
return dependants
|
||||
}
|
||||
|
||||
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
|
||||
ret := make([]string, 0)
|
||||
appendArray := func(label string, array []string, sort bool) {
|
||||
@@ -339,6 +368,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
|
||||
if len(dependants) > 0 {
|
||||
appendArray("Dependant packages", dependants, false)
|
||||
}
|
||||
optionalDependants := entry.GetEntryOptionalDependants()
|
||||
if len(optionalDependants) > 0 {
|
||||
appendArray("Optionally dependant packages", optionalDependants, false)
|
||||
}
|
||||
appendArray("Conflicting packages", entry.Info.Conflicts, true)
|
||||
appendArray("Provided packages", entry.Info.Provides, true)
|
||||
appendArray("Replaces packages", entry.Info.Replaces, true)
|
||||
|
||||
@@ -217,3 +217,46 @@ func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []s
|
||||
|
||||
return dependants
|
||||
}
|
||||
|
||||
func (pkgInfo *PackageInfo) GetPackageOptionalDependants(rootDir string) (dependants []string) {
|
||||
// Get installed package names
|
||||
pkgs, err := GetInstalledPackages(rootDir)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Loop through all installed packages
|
||||
for _, installedPkgName := range pkgs {
|
||||
// Get installed BPM package
|
||||
installedPkg := GetPackage(installedPkgName, rootDir)
|
||||
if installedPkg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip iteration if comparing the same packages
|
||||
if installedPkg.PkgInfo.Name == pkgInfo.Name {
|
||||
continue
|
||||
}
|
||||
|
||||
// Add installed package to list if its optional dependencies include pkgName
|
||||
if slices.ContainsFunc(installedPkg.PkgInfo.OptionalDepends, func(n string) bool {
|
||||
return n == pkgInfo.Name
|
||||
}) {
|
||||
dependants = append(dependants, installedPkgName)
|
||||
continue
|
||||
}
|
||||
|
||||
// Loop through each virtual package
|
||||
for _, vpkg := range pkgInfo.Provides {
|
||||
// Add installed package to list if its optional dependencies contain a provided virtual package
|
||||
if slices.ContainsFunc(installedPkg.PkgInfo.OptionalDepends, func(n string) bool {
|
||||
return n == vpkg
|
||||
}) {
|
||||
dependants = append(dependants, installedPkgName)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dependants
|
||||
}
|
||||
|
||||
@@ -545,6 +545,10 @@ func (bpmpkg *BPMPackage) CreateReadableInfo(rootDir string, humanReadableSize b
|
||||
if len(dependants) > 0 {
|
||||
appendArray("Dependant packages", dependants)
|
||||
}
|
||||
optionalDependants := bpmpkg.PkgInfo.GetPackageOptionalDependants(rootDir)
|
||||
if len(optionalDependants) > 0 {
|
||||
appendArray("Optionally dependant packages", optionalDependants)
|
||||
}
|
||||
appendArray("Conflicting packages", bpmpkg.PkgInfo.Conflicts)
|
||||
appendArray("Provided packages", bpmpkg.PkgInfo.Provides)
|
||||
appendArray("Replaces packages", bpmpkg.PkgInfo.Replaces)
|
||||
|
||||
Reference in New Issue
Block a user