1
0
mirror of https://github.com/Jguer/yay.git synced 2025-08-14 02:27:11 +02:00

Rework editing and diff showing

Clean build needs to happen before downloading pkgbuilds so that they
can be deletd before downloading.

Editing and diff viewing needs to happen after downloading the
pkgbuilds.

Prevously we asked to clean and edit at the same time. Then clean,
download pkgbuilds and open the editor.

This poeses a problem for diff viewing and editing. It's likley that the
user will see the diff and use that to decide if they want to edit the
pkgbuild. Using the current method, the user will be asked to view diffs
and edit before actually seeing any diffs.

Instead split cleaning diff showing and editing to three seperate menus
in the following order:
	show clean menu
	clean
	download pkgbuilds
	show diff menu
	show diffs
	show edit menu
	edit pkgbuilds

Also each menu is seperatly enableable. By default only the diff menu is
shows. If the user wishes to clean build, edit pkgbuilds or disable
diffs then the user can use the --[no]{clean,diff,edit}menu flags. This
replaces the --[no]showdiffs flags.
This commit is contained in:
morganamilo 2018-06-10 15:56:57 +01:00
parent 00da26a3ce
commit 8430c41be9
No known key found for this signature in database
GPG Key ID: 6FE9E7996B0B082E
3 changed files with 126 additions and 68 deletions

16
cmd.go
View File

@ -313,10 +313,18 @@ func handleConfig(option, value string) bool {
config.PGPFetch = true config.PGPFetch = true
case "nopgpfetch": case "nopgpfetch":
config.PGPFetch = false config.PGPFetch = false
case "showdiffs": case "cleanmenu":
config.ShowDiffs = true config.CleanMenu = true
case "noshowdiffs": case "nocleanmenu":
config.ShowDiffs = false config.CleanMenu = false
case "diffmenu":
config.DiffMenu = true
case "nodiffmenu":
config.DiffMenu = false
case "editmenu":
config.EditMenu = true
case "noeditmenu":
config.EditMenu = false
case "a", "aur": case "a", "aur":
mode = ModeAUR mode = ModeAUR
case "repo": case "repo":

View File

@ -65,6 +65,9 @@ type Configuration struct {
Provides bool `json:"provides"` Provides bool `json:"provides"`
PGPFetch bool `json:"pgpfetch"` PGPFetch bool `json:"pgpfetch"`
ShowDiffs bool `json:"showdifs"` ShowDiffs bool `json:"showdifs"`
CleanMenu bool `json:"cleanmenu"`
DiffMenu bool `json:"diffmenu"`
EditMenu bool `json:"editmenu"`
} }
var version = "5.688" var version = "5.688"
@ -168,7 +171,9 @@ func defaultSettings(config *Configuration) {
config.AnswerUpgrade = "" config.AnswerUpgrade = ""
config.GitClone = true config.GitClone = true
config.Provides = true config.Provides = true
config.ShowDiffs = true config.CleanMenu = false
config.DiffMenu = true
config.EditMenu = false
} }
// Editor returns the preferred system editor. // Editor returns the preferred system editor.

View File

@ -18,8 +18,6 @@ func install(parser *arguments) error {
var err error var err error
var incompatible stringSet var incompatible stringSet
var do *depOrder var do *depOrder
var toClean []*rpc.Pkg
var toEdit []*rpc.Pkg
var aurUp upSlice var aurUp upSlice
var repoUp upSlice var repoUp upSlice
@ -148,12 +146,15 @@ func install(parser *arguments) error {
} }
} }
toClean, toEdit, err = cleanEditNumberMenu(do.Aur, do.Bases, remoteNamesCache) if config.CleanMenu {
if err != nil { askClean := pkgbuildNumberMenu(do.Aur, do.Bases, remoteNamesCache)
return err toClean, err := cleanNumberMenu(do.Aur, do.Bases, remoteNamesCache, askClean)
} if err != nil {
return err
}
cleanBuilds(toClean) cleanBuilds(toClean)
}
toSkip := pkgBuildsToSkip(do.Aur, targets) toSkip := pkgBuildsToSkip(do.Aur, targets)
cloned, err := downloadPkgBuilds(do.Aur, do.Bases, toSkip) cloned, err := downloadPkgBuilds(do.Aur, do.Bases, toSkip)
@ -161,18 +162,43 @@ func install(parser *arguments) error {
return err return err
} }
if len(toEdit) > 0 { var toDiff []*rpc.Pkg
if config.ShowDiffs { var toEdit []*rpc.Pkg
err = showPkgBuildDiffs(toEdit, do.Bases, cloned)
} else { if config.DiffMenu {
err = editPkgBuilds(toEdit, do.Bases) pkgbuildNumberMenu(do.Aur, do.Bases, remoteNamesCache)
} toDiff, err = diffNumberMenu(do.Aur, do.Bases, remoteNamesCache)
if err != nil { if err != nil {
return err return err
} }
if len(toDiff) > 0 {
err = showPkgBuildDiffs(toDiff, do.Bases, cloned)
if err != nil {
return err
}
}
}
if config.EditMenu {
pkgbuildNumberMenu(do.Aur, do.Bases, remoteNamesCache)
toEdit, err = editNumberMenu(do.Aur, do.Bases, remoteNamesCache)
if err != nil {
return err
}
if len(toEdit) > 0 {
err = editPkgBuilds(toEdit, do.Bases)
if err != nil {
return err
}
}
}
if len(toDiff) > 0 || len(toEdit) > 0 {
oldValue := config.NoConfirm oldValue := config.NoConfirm
config.NoConfirm = false config.NoConfirm = false
fmt.Println()
if !continueTask(bold(green("Proceed with install?")), "nN") { if !continueTask(bold(green("Proceed with install?")), "nN") {
return fmt.Errorf("Aborting due to user") return fmt.Errorf("Aborting due to user")
} }
@ -355,13 +381,10 @@ func parsePackageList(dir string) (map[string]string, string, error) {
return pkgdests, version, nil return pkgdests, version, nil
} }
func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed stringSet) ([]*rpc.Pkg, []*rpc.Pkg, error) { func pkgbuildNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed stringSet) bool {
toPrint := "" toPrint := ""
askClean := false askClean := false
toClean := make([]*rpc.Pkg, 0)
toEdit := make([]*rpc.Pkg, 0)
for n, pkg := range pkgs { for n, pkg := range pkgs {
dir := filepath.Join(config.BuildDir, pkg.PackageBase) dir := filepath.Join(config.BuildDir, pkg.PackageBase)
@ -381,62 +404,84 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
fmt.Print(toPrint) fmt.Print(toPrint)
if askClean { return askClean
fmt.Println(bold(green(arrow + " Packages to cleanBuild?"))) }
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + "[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"))
fmt.Print(bold(green(arrow + " ")))
cleanInput, err := getInput(config.AnswerClean)
if err != nil {
return nil, nil, err
}
cInclude, cExclude, cOtherInclude, cOtherExclude := parseNumberMenu(cleanInput) func cleanNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed stringSet, hasClean bool) ([]*rpc.Pkg, error) {
cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0 toClean := make([]*rpc.Pkg, 0)
if cOtherInclude.get("abort") || cOtherInclude.get("ab") { if !hasClean {
return nil, nil, fmt.Errorf("Aborting due to user") return toClean, nil
} }
if !cOtherInclude.get("n") && !cOtherInclude.get("none") { fmt.Println(bold(green(arrow + " Packages to cleanBuild?")))
for i, pkg := range pkgs { fmt.Println(bold(green(arrow) + cyan(" [N]one ") + "[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"))
dir := filepath.Join(config.BuildDir, pkg.PackageBase) fmt.Print(bold(green(arrow + " ")))
if _, err := os.Stat(dir); os.IsNotExist(err) { cleanInput, err := getInput(config.AnswerClean)
continue if err != nil {
} return nil, err
}
if !cIsInclude && cExclude.get(len(pkgs)-i) { cInclude, cExclude, cOtherInclude, cOtherExclude := parseNumberMenu(cleanInput)
continue cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0
}
if installed.get(pkg.Name) && (cOtherInclude.get("i") || cOtherInclude.get("installed")) { if cOtherInclude.get("abort") || cOtherInclude.get("ab") {
toClean = append(toClean, pkg) return nil, fmt.Errorf("Aborting due to user")
continue }
}
if !installed.get(pkg.Name) && (cOtherInclude.get("no") || cOtherInclude.get("notinstalled")) { if !cOtherInclude.get("n") && !cOtherInclude.get("none") {
toClean = append(toClean, pkg) for i, pkg := range pkgs {
continue dir := filepath.Join(config.BuildDir, pkg.PackageBase)
} if _, err := os.Stat(dir); os.IsNotExist(err) {
continue
}
if cOtherInclude.get("a") || cOtherInclude.get("all") { if !cIsInclude && cExclude.get(len(pkgs)-i) {
toClean = append(toClean, pkg) continue
continue }
}
if cIsInclude && (cInclude.get(len(pkgs)-i) || cOtherInclude.get(pkg.PackageBase)) { if installed.get(pkg.Name) && (cOtherInclude.get("i") || cOtherInclude.get("installed")) {
toClean = append(toClean, pkg) toClean = append(toClean, pkg)
continue continue
} }
if !cIsInclude && (!cExclude.get(len(pkgs)-i) && !cOtherExclude.get(pkg.PackageBase)) { if !installed.get(pkg.Name) && (cOtherInclude.get("no") || cOtherInclude.get("notinstalled")) {
toClean = append(toClean, pkg) toClean = append(toClean, pkg)
continue continue
} }
if cOtherInclude.get("a") || cOtherInclude.get("all") {
toClean = append(toClean, pkg)
continue
}
if cIsInclude && (cInclude.get(len(pkgs)-i) || cOtherInclude.get(pkg.PackageBase)) {
toClean = append(toClean, pkg)
continue
}
if !cIsInclude && (!cExclude.get(len(pkgs)-i) && !cOtherExclude.get(pkg.PackageBase)) {
toClean = append(toClean, pkg)
continue
} }
} }
} }
if config.ShowDiffs { return toClean, nil
}
func editNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed stringSet) ([]*rpc.Pkg, error) {
return editDiffNumberMenu(pkgs, bases, installed, false)
}
func diffNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed stringSet) ([]*rpc.Pkg, error) {
return editDiffNumberMenu(pkgs, bases, installed, true)
}
func editDiffNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed stringSet, diff bool) ([]*rpc.Pkg, error) {
toEdit := make([]*rpc.Pkg, 0)
if diff {
fmt.Println(bold(green(arrow + " Diffs to show?"))) fmt.Println(bold(green(arrow + " Diffs to show?")))
} else { } else {
fmt.Println(bold(green(arrow + " PKGBUILDs to edit?"))) fmt.Println(bold(green(arrow + " PKGBUILDs to edit?")))
@ -447,14 +492,14 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
editInput, err := getInput(config.AnswerEdit) editInput, err := getInput(config.AnswerEdit)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
eInclude, eExclude, eOtherInclude, eOtherExclude := parseNumberMenu(editInput) eInclude, eExclude, eOtherInclude, eOtherExclude := parseNumberMenu(editInput)
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, nil, fmt.Errorf("Aborting due to user") return nil, fmt.Errorf("Aborting due to user")
} }
if !eOtherInclude.get("n") && !eOtherInclude.get("none") { if !eOtherInclude.get("n") && !eOtherInclude.get("none") {
@ -488,7 +533,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
} }
} }
return toClean, toEdit, nil return toEdit, nil
} }
func cleanBuilds(pkgs []*rpc.Pkg) { func cleanBuilds(pkgs []*rpc.Pkg) {