mirror of
https://github.com/Jguer/yay
synced 2024-10-05 23:59:13 +00:00
chore(menus): squish clean menu into diff/edit menu
This commit is contained in:
parent
49577191c6
commit
e4b1cb6e7d
|
@ -9,75 +9,10 @@ import (
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v11/pkg/dep"
|
"github.com/Jguer/yay/v11/pkg/dep"
|
||||||
"github.com/Jguer/yay/v11/pkg/intrange"
|
|
||||||
"github.com/Jguer/yay/v11/pkg/settings"
|
|
||||||
"github.com/Jguer/yay/v11/pkg/stringset"
|
"github.com/Jguer/yay/v11/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v11/pkg/text"
|
"github.com/Jguer/yay/v11/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cleanNumberMenu(buildDir string, bases []dep.Base,
|
|
||||||
installed stringset.StringSet, answerClean string, noConfirm bool) ([]dep.Base, error) {
|
|
||||||
toClean := make([]dep.Base, 0)
|
|
||||||
|
|
||||||
text.Infoln(gotext.Get("Packages to cleanBuild?"))
|
|
||||||
text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
|
|
||||||
|
|
||||||
cleanInput, err := text.GetInput(answerClean, noConfirm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cInclude, cExclude, cOtherInclude, cOtherExclude := intrange.ParseNumberMenu(cleanInput)
|
|
||||||
cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0
|
|
||||||
|
|
||||||
if cOtherInclude.Get("abort") || cOtherInclude.Get("ab") {
|
|
||||||
return nil, settings.ErrUserAbort{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cOtherInclude.Get("n") && !cOtherInclude.Get("none") {
|
|
||||||
for i, base := range bases {
|
|
||||||
pkg := base.Pkgbase()
|
|
||||||
anyInstalled := base.AnyIsInSet(installed)
|
|
||||||
|
|
||||||
dir := filepath.Join(buildDir, pkg)
|
|
||||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cIsInclude && cExclude.Get(len(bases)-i) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if anyInstalled && (cOtherInclude.Get("i") || cOtherInclude.Get("installed")) {
|
|
||||||
toClean = append(toClean, base)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !anyInstalled && (cOtherInclude.Get("no") || cOtherInclude.Get("notinstalled")) {
|
|
||||||
toClean = append(toClean, base)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if cOtherInclude.Get("a") || cOtherInclude.Get("all") {
|
|
||||||
toClean = append(toClean, base)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if cIsInclude && (cInclude.Get(len(bases)-i) || cOtherInclude.Get(pkg)) {
|
|
||||||
toClean = append(toClean, base)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cIsInclude && (!cExclude.Get(len(bases)-i) && !cOtherExclude.Get(pkg)) {
|
|
||||||
toClean = append(toClean, base)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return toClean, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func anyExistInCache(buildDir string, bases []dep.Base) bool {
|
func anyExistInCache(buildDir string, bases []dep.Base) bool {
|
||||||
for _, base := range bases {
|
for _, base := range bases {
|
||||||
pkg := base.Pkgbase()
|
pkg := base.Pkgbase()
|
||||||
|
@ -91,15 +26,23 @@ func anyExistInCache(buildDir string, bases []dep.Base) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func Clean(cleanMenuOption bool, buildDir string, aurBases []dep.Base,
|
func Clean(cleanMenuOption bool, buildDir string, bases []dep.Base,
|
||||||
installed stringset.StringSet, noConfirm bool, answerClean string) error {
|
installed stringset.StringSet, noConfirm bool, answerClean string) error {
|
||||||
if !(cleanMenuOption && anyExistInCache(buildDir, aurBases)) {
|
if !(cleanMenuOption && anyExistInCache(buildDir, bases)) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgbuildNumberMenu(buildDir, aurBases, installed)
|
skipFunc := func(pkg string) bool {
|
||||||
|
dir := filepath.Join(buildDir, pkg)
|
||||||
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
toClean, errClean := cleanNumberMenu(buildDir, aurBases, installed, answerClean, noConfirm)
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
toClean, errClean := selectionMenu(buildDir, bases, installed, gotext.Get("Packages to cleanBuild?"),
|
||||||
|
noConfirm, answerClean, skipFunc)
|
||||||
if errClean != nil {
|
if errClean != nil {
|
||||||
return errClean
|
return errClean
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,9 +154,8 @@ func Diff(ctx context.Context, cmdBuilder exe.ICmdBuilder,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgbuildNumberMenu(buildDir, bases, installed)
|
toDiff, errMenu := selectionMenu(buildDir, bases, installed, gotext.Get("Diffs to show?"),
|
||||||
|
noConfirm, diffDefaultAnswer, nil)
|
||||||
toDiff, errMenu := editDiffNumberMenu(bases, installed, gotext.Get("Diffs to show?"), noConfirm, diffDefaultAnswer)
|
|
||||||
if errMenu != nil || len(toDiff) == 0 {
|
if errMenu != nil || len(toDiff) == 0 {
|
||||||
return errMenu
|
return errMenu
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,9 +119,8 @@ func Edit(editMenuOption bool, buildDir string, bases []dep.Base, editorConfig,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgbuildNumberMenu(buildDir, bases, installed)
|
toEdit, errMenu := selectionMenu(buildDir, bases,
|
||||||
|
installed, gotext.Get("PKGBUILDs to edit?"), noConfirm, editDefaultAnswer, nil)
|
||||||
toEdit, errMenu := editDiffNumberMenu(bases, installed, gotext.Get("PKGBUILDs to edit?"), noConfirm, editDefaultAnswer)
|
|
||||||
if errMenu != nil || len(toEdit) == 0 {
|
if errMenu != nil || len(toEdit) == 0 {
|
||||||
return errMenu
|
return errMenu
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,28 +38,38 @@ func pkgbuildNumberMenu(buildDir string, bases []dep.Base, installed stringset.S
|
||||||
fmt.Print(toPrint)
|
fmt.Print(toPrint)
|
||||||
}
|
}
|
||||||
|
|
||||||
func editDiffNumberMenu(bases []dep.Base, installed stringset.StringSet,
|
func selectionMenu(buildDir string, bases []dep.Base, installed stringset.StringSet,
|
||||||
message string, noConfirm bool, defaultAnswer string) ([]dep.Base, error) {
|
message string, noConfirm bool, defaultAnswer string, skipFunc func(string) bool) ([]dep.Base, error) {
|
||||||
toEdit := make([]dep.Base, 0)
|
selected := make([]dep.Base, 0)
|
||||||
|
|
||||||
|
pkgbuildNumberMenu(buildDir, bases, installed)
|
||||||
|
|
||||||
text.Infoln(message)
|
text.Infoln(message)
|
||||||
text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
|
text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
|
||||||
|
|
||||||
editInput, err := text.GetInput(defaultAnswer, noConfirm)
|
selectInput, err := text.GetInput(defaultAnswer, noConfirm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
eInclude, eExclude, eOtherInclude, eOtherExclude := intrange.ParseNumberMenu(editInput)
|
eInclude, eExclude, eOtherInclude, eOtherExclude := intrange.ParseNumberMenu(selectInput)
|
||||||
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
|
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
|
||||||
|
|
||||||
if eOtherInclude.Get("abort") || eOtherInclude.Get("ab") {
|
if eOtherInclude.Get("abort") || eOtherInclude.Get("ab") {
|
||||||
return nil, &settings.ErrUserAbort{}
|
return nil, settings.ErrUserAbort{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if eOtherInclude.Get("n") || eOtherInclude.Get("none") {
|
||||||
|
return selected, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !eOtherInclude.Get("n") && !eOtherInclude.Get("none") {
|
|
||||||
for i, base := range bases {
|
for i, base := range bases {
|
||||||
pkg := base.Pkgbase()
|
pkg := base.Pkgbase()
|
||||||
|
|
||||||
|
if skipFunc != nil && skipFunc(pkg) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
anyInstalled := base.AnyIsInSet(installed)
|
anyInstalled := base.AnyIsInSet(installed)
|
||||||
|
|
||||||
if !eIsInclude && eExclude.Get(len(bases)-i) {
|
if !eIsInclude && eExclude.Get(len(bases)-i) {
|
||||||
|
@ -67,29 +77,28 @@ func editDiffNumberMenu(bases []dep.Base, installed stringset.StringSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
if anyInstalled && (eOtherInclude.Get("i") || eOtherInclude.Get("installed")) {
|
if anyInstalled && (eOtherInclude.Get("i") || eOtherInclude.Get("installed")) {
|
||||||
toEdit = append(toEdit, base)
|
selected = append(selected, base)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !anyInstalled && (eOtherInclude.Get("no") || eOtherInclude.Get("notinstalled")) {
|
if !anyInstalled && (eOtherInclude.Get("no") || eOtherInclude.Get("notinstalled")) {
|
||||||
toEdit = append(toEdit, base)
|
selected = append(selected, base)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if eOtherInclude.Get("a") || eOtherInclude.Get("all") {
|
if eOtherInclude.Get("a") || eOtherInclude.Get("all") {
|
||||||
toEdit = append(toEdit, base)
|
selected = append(selected, base)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if eIsInclude && (eInclude.Get(len(bases)-i) || eOtherInclude.Get(pkg)) {
|
if eIsInclude && (eInclude.Get(len(bases)-i) || eOtherInclude.Get(pkg)) {
|
||||||
toEdit = append(toEdit, base)
|
selected = append(selected, base)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !eIsInclude && (!eExclude.Get(len(bases)-i) && !eOtherExclude.Get(pkg)) {
|
if !eIsInclude && (!eExclude.Get(len(bases)-i) && !eOtherExclude.Get(pkg)) {
|
||||||
toEdit = append(toEdit, base)
|
selected = append(selected, base)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return toEdit, nil
|
return selected, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,5 @@ func sysupgradeTargets(ctx context.Context, dbExecutor db.Executor,
|
||||||
|
|
||||||
warnings.Print()
|
warnings.Print()
|
||||||
|
|
||||||
ignore, targets, errUp := upgradePkgsMenu(aurUp, repoUp)
|
return upgradePkgsMenu(aurUp, repoUp)
|
||||||
|
|
||||||
return ignore, targets, errUp
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue