Skip to content

Commit

Permalink
feat(local_install): add choice menu for yay -Bi (Jguer#1903)
Browse files Browse the repository at this point in the history
add choice menu for yay -Bi
  • Loading branch information
Jguer authored Jan 23, 2023
1 parent 4626a04 commit 4f50b79
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions local_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func TestIntegrationLocalInstall(t *testing.T) {
cmdArgs.AddArg("B")
cmdArgs.AddArg("i")
cmdArgs.AddTarget("testdata/jfin")
settings.NoConfirm = true
defer func() { settings.NoConfirm = false }()
db := &mock.DBExecutor{
AlpmArchitecturesFn: func() ([]string, error) {
return []string{"x86_64"}, nil
Expand Down Expand Up @@ -223,6 +225,8 @@ func TestIntegrationLocalInstallMissingDep(t *testing.T) {
cmdArgs.AddArg("B")
cmdArgs.AddArg("i")
cmdArgs.AddTarget("testdata/jfin")
settings.NoConfirm = true
defer func() { settings.NoConfirm = false }()
db := &mock.DBExecutor{
AlpmArchitecturesFn: func() ([]string, error) {
return []string{"x86_64"}, nil
Expand Down
51 changes: 50 additions & 1 deletion pkg/dep/dep_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/intrange"
aur "github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/topo"
Expand Down Expand Up @@ -195,6 +196,38 @@ func (g *Grapher) GraphFromTargets(ctx context.Context,
return graph, nil
}

func (g *Grapher) pickSrcInfoPkgs(pkgs []aurc.Pkg) ([]aurc.Pkg, error) {
final := make([]aurc.Pkg, 0, len(pkgs))
for i := range pkgs {
fmt.Fprintln(os.Stdout, text.Magenta(strconv.Itoa(i+1)+" ")+text.Bold(pkgs[i].Name)+
" "+text.Cyan(pkgs[i].Version))
fmt.Fprintln(os.Stdout, " "+pkgs[i].Description)
}
text.Infoln(gotext.Get("Packages to exclude") + " (eg: \"1 2 3\", \"1-3\", \"^4\"):")

numberBuf, err := text.GetInput("", g.noConfirm)
if err != nil {
return nil, err
}

include, exclude, _, otherExclude := intrange.ParseNumberMenu(numberBuf)
isInclude := len(exclude) == 0 && len(otherExclude) == 0

for i := 1; i <= len(pkgs); i++ {
target := i - 1

if isInclude && !include.Get(i) {
final = append(final, pkgs[target])
}

if !isInclude && (exclude.Get(i)) {
final = append(final, pkgs[target])
}
}

return final, nil
}

func (g *Grapher) GraphFromSrcInfo(ctx context.Context, graph *topo.Graph[string, *InstallInfo], pkgBuildDir string,
pkgbuild *gosrc.Srcinfo,
) (*topo.Graph[string, *InstallInfo], error) {
Expand All @@ -207,6 +240,14 @@ func (g *Grapher) GraphFromSrcInfo(ctx context.Context, graph *topo.Graph[string
return nil, err
}

if len(aurPkgs) > 1 {
var errPick error
aurPkgs, errPick = g.pickSrcInfoPkgs(aurPkgs)
if errPick != nil {
return nil, errPick
}
}

for i := range aurPkgs {
pkg := &aurPkgs[i]

Expand Down Expand Up @@ -485,6 +526,14 @@ func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]au

alpmArch = append(alpmArch, "") // srcinfo assumes no value as ""

getDesc := func(pkg *gosrc.Package) string {
if pkg.Pkgdesc != "" {
return pkg.Pkgdesc
}

return srcInfo.Pkgdesc
}

for i := range srcInfo.Packages {
pkg := &srcInfo.Packages[i]

Expand All @@ -494,7 +543,7 @@ func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]au
PackageBaseID: 0,
PackageBase: srcInfo.Pkgbase,
Version: srcInfo.Version(),
Description: pkg.Pkgdesc,
Description: getDesc(pkg),
URL: pkg.URL,
Depends: append(archStringToString(alpmArch, pkg.Depends),
archStringToString(alpmArch, srcInfo.Package.Depends)...),
Expand Down
1 change: 1 addition & 0 deletions pkg/query/mixed_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (s *MixedSourceQueryBuilder) GetTargets(include, exclude intrange.IntRanges
)

for i := 0; i <= s.Len(); i++ {
// FIXME: this is probably broken
target := i - 1
if s.bottomUp {
target = lenRes - i
Expand Down
2 changes: 1 addition & 1 deletion upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
fmt.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade.")))
allUp.Print()

text.Infoln(gotext.Get("Packages to exclude: (eg: \"1 2 3\", \"1-3\", \"^4\" or repo name)"))
text.Infoln(gotext.Get("Packages to exclude") + " (eg: \"1 2 3\", \"1-3\", \"^4\" or repo name):")

numbers, err := text.GetInput(config.AnswerUpgrade, settings.NoConfirm)
if err != nil {
Expand Down

0 comments on commit 4f50b79

Please sign in to comment.