mirror of
https://github.com/Jguer/yay
synced 2024-10-01 13:53:32 +00:00
chore(upgrade): add makedep explain to the upgrade menu (#2110)
* display required by * cutoff at 2
This commit is contained in:
parent
76e5ee1fa6
commit
4a9c736e2a
|
@ -26,6 +26,7 @@ type Upgrade struct {
|
|||
LocalVersion string
|
||||
RemoteVersion string
|
||||
Reason alpm.PkgReason
|
||||
Extra string // Extra information to be displayed
|
||||
}
|
||||
|
||||
type SyncUpgrade struct {
|
||||
|
|
|
@ -12,6 +12,16 @@ type (
|
|||
DepMap[T comparable] map[T]NodeSet[T]
|
||||
)
|
||||
|
||||
func (n NodeSet[T]) Slice() []T {
|
||||
var slice []T
|
||||
|
||||
for node := range n {
|
||||
slice = append(slice, node)
|
||||
}
|
||||
|
||||
return slice
|
||||
}
|
||||
|
||||
type NodeInfo[V any] struct {
|
||||
Color string
|
||||
Background string
|
||||
|
@ -253,10 +263,10 @@ func (g *Graph[T, V]) remove(node T) {
|
|||
}
|
||||
|
||||
func (g *Graph[T, V]) Dependencies(child T) NodeSet[T] {
|
||||
return g.buildTransitive(child, g.immediateDependencies)
|
||||
return g.buildTransitive(child, g.ImmediateDependencies)
|
||||
}
|
||||
|
||||
func (g *Graph[T, V]) immediateDependencies(node T) NodeSet[T] {
|
||||
func (g *Graph[T, V]) ImmediateDependencies(node T) NodeSet[T] {
|
||||
return g.dependencies[node]
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,10 @@ package upgrade
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
|
@ -20,6 +23,8 @@ import (
|
|||
"github.com/Jguer/yay/v12/pkg/vcs"
|
||||
)
|
||||
|
||||
const cutOffExtra = 2
|
||||
|
||||
type UpgradeService struct {
|
||||
grapher *dep.Grapher
|
||||
aurCache aur.QueryClient
|
||||
|
@ -188,9 +193,19 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
|
|||
repoUp = UpSlice{Up: make([]Upgrade, 0, graph.Len()), Repos: u.dbExecutor.Repos()}
|
||||
|
||||
_ = graph.ForEach(func(name string, info *dep.InstallInfo) error {
|
||||
alpmReason := alpm.PkgReasonExplicit
|
||||
if info.Reason == dep.Dep {
|
||||
alpmReason = alpm.PkgReasonDepend
|
||||
alpmReason := alpm.PkgReasonDepend
|
||||
if info.Reason == dep.Explicit {
|
||||
alpmReason = alpm.PkgReasonExplicit
|
||||
}
|
||||
|
||||
parents := graph.ImmediateDependencies(name)
|
||||
extra := ""
|
||||
if len(parents) > 0 && !info.Upgrade && info.Reason == dep.MakeDep {
|
||||
reducedParents := parents.Slice()[:int(math.Min(cutOffExtra, float64(len(parents))))]
|
||||
if len(parents) > cutOffExtra {
|
||||
reducedParents = append(reducedParents, "...")
|
||||
}
|
||||
extra = fmt.Sprintf(" (%s of %s)", dep.ReasonNames[info.Reason], strings.Join(reducedParents, ", "))
|
||||
}
|
||||
|
||||
if info.Source == dep.AUR {
|
||||
|
@ -205,6 +220,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
|
|||
Base: *info.AURBase,
|
||||
LocalVersion: info.LocalVersion,
|
||||
Reason: alpmReason,
|
||||
Extra: extra,
|
||||
})
|
||||
} else if info.Source == dep.Sync {
|
||||
repoUp.Up = append(repoUp.Up, Upgrade{
|
||||
|
@ -214,6 +230,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
|
|||
Base: "",
|
||||
LocalVersion: info.LocalVersion,
|
||||
Reason: alpmReason,
|
||||
Extra: extra,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -2,6 +2,7 @@ package upgrade
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
|
@ -112,18 +113,23 @@ func (u UpSlice) Print(logger *text.Logger) {
|
|||
longestVersion = intrange.Max(packVersionLen, longestVersion)
|
||||
}
|
||||
|
||||
lenUp := len(u.Up)
|
||||
longestNumber := len(fmt.Sprintf("%v", lenUp))
|
||||
namePadding := fmt.Sprintf("%%-%ds ", longestName)
|
||||
versionPadding := fmt.Sprintf("%%-%ds", longestVersion)
|
||||
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u.Up))))
|
||||
numberPadding := fmt.Sprintf("%%%dd ", longestNumber)
|
||||
|
||||
for k := range u.Up {
|
||||
upgrade := &u.Up[k]
|
||||
left, right := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
|
||||
|
||||
logger.Printf(text.Magenta(fmt.Sprintf(numberPadding, len(u.Up)-k)))
|
||||
logger.Printf(text.Magenta(fmt.Sprintf(numberPadding, lenUp-k)))
|
||||
|
||||
logger.Printf(namePadding, StylizedNameWithRepository(upgrade))
|
||||
|
||||
logger.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
|
||||
if upgrade.Extra != "" {
|
||||
logger.Println(strings.Repeat(" ", longestNumber), upgrade.Extra)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue