Add Explain() to Assertions and Packages

This commit is contained in:
Ettore Di Giacinto
2019-10-31 12:34:28 +01:00
parent 7f848ee5ef
commit e5db47a679
2 changed files with 38 additions and 0 deletions

View File

@@ -53,6 +53,7 @@ type Package interface {
GetUses() []string GetUses() []string
Yaml() ([]byte, error) Yaml() ([]byte, error)
Explain()
} }
type PackageSet interface { type PackageSet interface {
@@ -290,3 +291,23 @@ func (p *DefaultPackage) BuildFormula() ([]bf.Formula, error) {
} }
return formulas, nil return formulas, nil
} }
func (p *DefaultPackage) Explain() {
fmt.Println("====================")
fmt.Println("Name: ", p.GetName())
fmt.Println("Category: ", p.GetCategory())
fmt.Println("Version: ", p.GetVersion())
fmt.Println("Installed: ", p.IsSet)
for _, req := range p.GetRequires() {
fmt.Println("\t-> ", req)
}
for _, con := range p.GetConflicts() {
fmt.Println("\t!! ", con)
}
fmt.Println("====================")
}

View File

@@ -16,6 +16,8 @@
package solver package solver
import ( import (
"fmt"
pkg "github.com/mudler/luet/pkg/package" pkg "github.com/mudler/luet/pkg/package"
) )
@@ -40,3 +42,18 @@ func DecodeModel(model map[string]bool) ([]PackageAssert, error) {
} }
return ass, nil return ass, nil
} }
func (a *PackageAssert) Explain() {
fmt.Println(a.ToString())
a.Package.Explain()
}
func (a *PackageAssert) ToString() string {
var msg string
if a.Package.Flagged() {
msg = "installed"
} else {
msg = "not installed"
}
return fmt.Sprintf("%s/%s %s %s: %t", a.Package.GetCategory(), a.Package.GetName(), a.Package.GetVersion(), msg, a.Value)
}