yay/pkg/query/aur_warnings.go

69 lines
1.3 KiB
Go
Raw Normal View History

2020-07-10 02:36:45 +02:00
package query
import (
"fmt"
"strings"
2020-07-10 02:36:45 +02:00
"github.com/leonelquinteros/gotext"
"github.com/Jguer/yay/v10/pkg/stringset"
"github.com/Jguer/yay/v10/pkg/text"
)
type AURWarnings struct {
Orphans []string
OutOfDate []string
Missing []string
Ignore stringset.StringSet
}
func NewWarnings() *AURWarnings {
return &AURWarnings{Ignore: make(stringset.StringSet)}
}
func (warnings *AURWarnings) Print() {
normalMissing, debugMissing := filterDebugPkgs(warnings.Missing)
if len(normalMissing) > 0 {
2020-07-10 02:36:45 +02:00
text.Warn(gotext.Get("Missing AUR Packages:"))
printRange(normalMissing)
}
if len(debugMissing) > 0 {
text.Warn(gotext.Get("Missing AUR Debug Packages:"))
printRange(debugMissing)
2020-07-10 02:36:45 +02:00
}
if len(warnings.Orphans) > 0 {
text.Warn(gotext.Get("Orphaned AUR Packages:"))
printRange(warnings.Orphans)
}
if len(warnings.OutOfDate) > 0 {
text.Warn(gotext.Get("Flagged Out Of Date AUR Packages:"))
printRange(warnings.OutOfDate)
}
}
func filterDebugPkgs(names []string) (normal, debug []string) {
normal = make([]string, 0)
debug = make([]string, 0)
for _, name := range names {
if strings.HasSuffix(name, "-debug") {
debug = append(debug, name)
} else {
normal = append(normal, name)
}
}
return
}
2020-07-10 02:36:45 +02:00
func printRange(names []string) {
for _, name := range names {
fmt.Print(" " + text.Cyan(name))
}
fmt.Println()
}