Skip to content

Commit

Permalink
feat(new_install): show (Jguer#1915)
Browse files Browse the repository at this point in the history
* show new packages in upgrade form if they exist

* refactor up select

* remove unused graph parts

* readd len

* Complete upgrade graphing

* Extract to upgrade pkg

* remove unused dep method

* remove uneeded dep

* cleanup method

* specify io Reader for testing

* use specified input vector

* fix non-active devel

* test base cases

* add devel test cases

* add range tests

* add logger struct

* use logger struct in upgrade

* follow golangci recommendations

* update deps

* update golangci
  • Loading branch information
Jguer authored Feb 17, 2023
1 parent 4f50b79 commit 0bf4c2e
Show file tree
Hide file tree
Showing 26 changed files with 936 additions and 338 deletions.
2 changes: 1 addition & 1 deletion ci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ COPY go.mod .
RUN pacman-key --init && pacman -Sy && pacman -S --overwrite=* --noconfirm archlinux-keyring && \
pacman -Su --overwrite=* --needed --noconfirm doxygen meson asciidoc go git gcc make sudo base-devel && \
rm -rfv /var/cache/pacman/* /var/lib/pacman/sync/* && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.1 && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.1 && \
go mod download
8 changes: 4 additions & 4 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ func getFilter(cmdArgs *parser.Arguments) (upgrade.Filter, error) {
case deps && explicit:
return nil, errors.New(gotext.Get("invalid option: '--deps' and '--explicit' may not be used together"))
case deps:
return func(pkg upgrade.Upgrade) bool {
return func(pkg *upgrade.Upgrade) bool {
return pkg.Reason == alpm.PkgReasonDepend
}, nil
case explicit:
return func(pkg upgrade.Upgrade) bool {
return func(pkg *upgrade.Upgrade) bool {
return pkg.Reason == alpm.PkgReasonExplicit
}, nil
}

return func(pkg upgrade.Upgrade) bool {
return func(pkg *upgrade.Upgrade) bool {
return true
}, nil
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func displayNumberMenu(ctx context.Context, pkgS []string, dbExecutor db.Executo

text.Infoln(gotext.Get("Packages to install (eg: 1 2 3, 1-3 or ^4)"))

numberBuf, err := text.GetInput("", false)
numberBuf, err := text.GetInput(os.Stdin, "", false)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
github.com/leonelquinteros/gotext v1.5.1
github.com/stretchr/testify v1.8.1
golang.org/x/sys v0.3.0
golang.org/x/term v0.3.0
golang.org/x/text v0.5.0 // indirect
golang.org/x/sys v0.5.0
golang.org/x/term v0.5.0
golang.org/x/text v0.7.0 // indirect
gopkg.in/h2non/gock.v1 v1.1.2
)

Expand All @@ -28,7 +28,7 @@ require (
github.com/deckarep/golang-set/v2 v2.1.0
github.com/itchyny/gojq v0.12.11 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/ohler55/ojg v1.15.0 // indirect
github.com/ohler55/ojg v1.17.4 // indirect
)

go 1.19
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/ohler55/ojg v1.15.0 h1:Z95FvBiMsMOOGP9Nzv5OVV4ND2KnEMxk0GOS8Kvcahg=
github.com/ohler55/ojg v1.15.0/go.mod h1:7Ghirupn8NC8hSSDpI0gcjorPxj+vSVIONDWfliHR1k=
github.com/ohler55/ojg v1.17.4 h1:6Ss87DyAZHU0ODZu6Cmuahj5UiVaRD1n8C4KNm0qMYg=
github.com/ohler55/ojg v1.17.4/go.mod h1:7Ghirupn8NC8hSSDpI0gcjorPxj+vSVIONDWfliHR1k=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -62,15 +64,21 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/graph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ func graphPackage(
}

fmt.Fprintln(os.Stdout, graph.String())
fmt.Fprintln(os.Stdout, "\nlayers\n", graph.TopoSortedLayers())
fmt.Fprintln(os.Stdout, "\ninverted order\n", graph.TopoSorted())
fmt.Fprintln(os.Stdout, "\nlayers map\n", graph.TopoSortedLayerMap(nil))

return nil
Expand Down
9 changes: 8 additions & 1 deletion pkg/db/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ type Upgrade struct {
Reason alpm.PkgReason
}

type SyncUpgrade struct {
Package alpm.IPackage
LocalVersion string
Reason alpm.PkgReason
}

type Executor interface {
AlpmArchitectures() ([]string, error)
BiggestPackages() []IPackage
Expand All @@ -45,7 +51,8 @@ type Executor interface {
PackageProvides(IPackage) []Depend
PackagesFromGroup(string) []IPackage
RefreshHandle() error
RepoUpgrades(bool) ([]Upgrade, error)
SyncUpgrades(enableDowngrade bool) (
map[string]SyncUpgrade, error)
Repos() []string
SatisfierFromDB(string, string) IPackage
SyncPackage(string) IPackage
Expand Down
32 changes: 15 additions & 17 deletions pkg/db/ialpm/alpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/upgrade"
)

type AlpmExecutor struct {
Expand Down Expand Up @@ -204,7 +203,7 @@ func (ae *AlpmExecutor) questionCallback() func(question alpm.QuestionAny) {
break
}

numberBuf, err := text.GetInput("", false)
numberBuf, err := text.GetInput(os.Stdin, "", false)
if err != nil {
text.Errorln(err)
break
Expand Down Expand Up @@ -407,26 +406,27 @@ func (ae *AlpmExecutor) PackageGroups(pkg alpm.IPackage) []string {

// upRepo gathers local packages and checks if they have new versions.
// Output: Upgrade type package list.
func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) ([]db.Upgrade, error) {
func (ae *AlpmExecutor) SyncUpgrades(enableDowngrade bool) (
map[string]db.SyncUpgrade, error,
) {
ups := map[string]db.SyncUpgrade{}
var errReturn error

slice := []db.Upgrade{}

localDB, errDB := ae.handle.LocalDB()
if errDB != nil {
return slice, errDB
return ups, errDB
}

if err := ae.handle.TransInit(alpm.TransFlagNoLock); err != nil {
return slice, err
return ups, err
}

defer func() {
errReturn = ae.handle.TransRelease()
}()

if err := ae.handle.SyncSysupgrade(enableDowngrade); err != nil {
return slice, err
return ups, err
}

_ = ae.handle.TransGetAdd().ForEach(func(pkg alpm.IPackage) error {
Expand All @@ -438,18 +438,16 @@ func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) ([]db.Upgrade, error)
reason = localPkg.Reason()
}

slice = append(slice, upgrade.Upgrade{
Name: pkg.Name(),
Base: pkg.Base(),
Repository: pkg.DB().Name(),
LocalVersion: localVer,
RemoteVersion: pkg.Version(),
Reason: reason,
})
ups[pkg.Name()] = db.SyncUpgrade{
Package: pkg,
Reason: reason,
LocalVersion: localVer,
}

return nil
})

return slice, errReturn
return ups, errReturn
}

func (ae *AlpmExecutor) BiggestPackages() []alpm.IPackage {
Expand Down
52 changes: 38 additions & 14 deletions pkg/db/mock/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,30 @@ type (

type DBExecutor struct {
db.Executor
IsCorrectVersionInstalledFn func(string, string) bool
SyncPackageFn func(string) IPackage
PackagesFromGroupFn func(string) []IPackage
LocalSatisfierExistsFn func(string) bool
SyncSatisfierFn func(string) IPackage
AlpmArchitecturesFn func() ([]string, error)
IsCorrectVersionInstalledFn func(string, string) bool
SyncPackageFn func(string) IPackage
PackagesFromGroupFn func(string) []IPackage
LocalSatisfierExistsFn func(string) bool
SyncSatisfierFn func(string) IPackage
AlpmArchitecturesFn func() ([]string, error)
InstalledRemotePackageNamesFn func() []string
InstalledRemotePackagesFn func() map[string]IPackage
SyncUpgradesFn func(bool) (map[string]db.SyncUpgrade, error)
ReposFn func() []string
}

func (t *DBExecutor) InstalledRemotePackageNames() []string {
if t.InstalledRemotePackageNamesFn != nil {
return t.InstalledRemotePackageNamesFn()
}
panic("implement me")
}

func (t *DBExecutor) InstalledRemotePackages() map[string]IPackage {
if t.InstalledRemotePackagesFn != nil {
return t.InstalledRemotePackagesFn()
}
panic("implement me")
}

func (t *DBExecutor) AlpmArchitectures() ([]string, error) {
Expand Down Expand Up @@ -93,40 +111,46 @@ func (t *DBExecutor) PackagesFromGroup(s string) []IPackage {
panic("implement me")
}

func (t DBExecutor) RefreshHandle() error {
func (t *DBExecutor) RefreshHandle() error {
panic("implement me")
}

func (t DBExecutor) RepoUpgrades(b bool) ([]Upgrade, error) {
func (t *DBExecutor) SyncUpgrades(b bool) (map[string]db.SyncUpgrade, error) {
if t.SyncUpgradesFn != nil {
return t.SyncUpgradesFn(b)
}
panic("implement me")
}

func (t DBExecutor) Repos() []string {
func (t *DBExecutor) Repos() []string {
if t.ReposFn != nil {
return t.ReposFn()
}
panic("implement me")
}

func (t DBExecutor) SatisfierFromDB(s, s2 string) IPackage {
func (t *DBExecutor) SatisfierFromDB(s, s2 string) IPackage {
panic("implement me")
}

func (t DBExecutor) SyncPackage(s string) IPackage {
func (t *DBExecutor) SyncPackage(s string) IPackage {
if t.SyncPackageFn != nil {
return t.SyncPackageFn(s)
}
panic("implement me")
}

func (t DBExecutor) SyncPackages(s ...string) []IPackage {
func (t *DBExecutor) SyncPackages(s ...string) []IPackage {
panic("implement me")
}

func (t DBExecutor) SyncSatisfier(s string) IPackage {
func (t *DBExecutor) SyncSatisfier(s string) IPackage {
if t.SyncSatisfierFn != nil {
return t.SyncSatisfierFn(s)
}
panic("implement me")
}

func (t DBExecutor) SyncSatisfierExists(s string) bool {
func (t *DBExecutor) SyncSatisfierExists(s string) bool {
panic("implement me")
}
2 changes: 1 addition & 1 deletion pkg/dep/depPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func providerMenu(dep string, providers providers, noConfirm bool) *query.Pkg {
return providers.Pkgs[0]
}

numberBuf, err := text.GetInput("", false)
numberBuf, err := text.GetInput(os.Stdin, "", false)
if err != nil {
fmt.Fprintln(os.Stderr, err)

Expand Down
Loading

0 comments on commit 0bf4c2e

Please sign in to comment.