Fix installation reason showing in 'info' subcommand when viewing not-installed package, database entry or BPM file

This commit is contained in:
EnumDev 2025-05-14 15:01:28 +03:00
parent d26d878308
commit bf2b4e95ac
2 changed files with 8 additions and 4 deletions

View File

@ -124,6 +124,7 @@ func resolveCommand() {
for n, pkg := range packages {
var info *bpmlib.PackageInfo
isFile := false
showInstallationReason := false
if showRepoInfo {
var err error
var entry *bpmlib.RepositoryEntry
@ -147,6 +148,7 @@ func resolveCommand() {
} else {
info = bpmlib.GetPackageInfo(pkg, rootDir)
}
showInstallationReason = true
}
if info == nil {
log.Fatalf("Error: package (%s) is not installed\n", pkg)
@ -161,7 +163,7 @@ func resolveCommand() {
}
fmt.Println("File: " + abs)
}
fmt.Println(bpmlib.CreateReadableInfo(true, true, true, info, rootDir))
fmt.Println(bpmlib.CreateReadableInfo(true, true, true, showInstallationReason, info, rootDir))
}
case list:
// Read local databases
@ -195,7 +197,7 @@ func resolveCommand() {
if n != 0 {
fmt.Println()
}
fmt.Println(bpmlib.CreateReadableInfo(true, true, true, info, rootDir))
fmt.Println(bpmlib.CreateReadableInfo(true, true, true, true, info, rootDir))
}
}
case search:

View File

@ -484,7 +484,7 @@ func ReadPackageInfo(contents string) (*PackageInfo, error) {
return pkgInfo, nil
}
func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, pkgInfo *PackageInfo, rootDir string) string {
func CreateReadableInfo(showArchitecture, showType, showPackageRelations, showInstallationReason bool, pkgInfo *PackageInfo, rootDir string) string {
ret := make([]string, 0)
appendArray := func(label string, array []string) {
if len(array) == 0 {
@ -524,7 +524,9 @@ func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, p
}
appendArray("Split Packages", splitPkgs)
}
ret = append(ret, "Installation Reason: "+string(GetInstallationReason(pkgInfo.Name, rootDir)))
if IsPackageInstalled(pkgInfo.Name, rootDir) && showInstallationReason {
ret = append(ret, "Installation Reason: "+string(GetInstallationReason(pkgInfo.Name, rootDir)))
}
return strings.Join(ret, "\n")
}