Skip to content

Commit

Permalink
Merge pull request Jguer#601 from xyproto/minor
Browse files Browse the repository at this point in the history
Only minor changes
  • Loading branch information
Morganamilo authored Aug 2, 2018
2 parents b848514 + e9d0b8b commit 0746d28
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 151 deletions.
135 changes: 68 additions & 67 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,80 @@ import (
)

func questionCallback(question alpm.QuestionAny) {
qi, err := question.QuestionInstallIgnorepkg()
if err == nil {
if qi, err := question.QuestionInstallIgnorepkg(); err == nil {
qi.SetInstall(true)
}

qp, err := question.QuestionSelectProvider()
if err == nil {
size := 0

qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
size++
return nil
})

fmt.Print(bold(cyan(":: ")))
str := bold(fmt.Sprintf(bold("There are %d providers available for %s:"), size, qp.Dep()))

size = 1
var db string

qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
thisDb := pkg.DB().Name()

if db != thisDb {
db = thisDb
str += bold(cyan("\n:: ")) + bold("Repository "+db+"\n ")
}
str += fmt.Sprintf("%d) %s ", size, pkg.Name())
size++
return nil
})

fmt.Println(str)

for {
fmt.Print("\nEnter a number (default=1): ")

if config.NoConfirm {
fmt.Println()
break
}

reader := bufio.NewReader(os.Stdin)
numberBuf, overflow, err := reader.ReadLine()

if err != nil {
fmt.Println(err)
break
}

if overflow {
fmt.Println("Input too long")
continue
}

if string(numberBuf) == "" {
break
}

num, err := strconv.Atoi(string(numberBuf))
if err != nil {
fmt.Printf("%s invalid number: %s\n", red("error:"), string(numberBuf))
continue
}

if num < 1 || num > size {
fmt.Printf("%s invalid value: %d is not between %d and %d\n", red("error:"), num, 1, size)
continue
}

qp.SetUseIndex(num - 1)
if err != nil {
return
}

size := 0

qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
size++
return nil
})

fmt.Print(bold(cyan(":: ")))
str := bold(fmt.Sprintf(bold("There are %d providers available for %s:"), size, qp.Dep()))

size = 1
var db string

qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
thisDb := pkg.DB().Name()

if db != thisDb {
db = thisDb
str += bold(cyan("\n:: ")) + bold("Repository "+db+"\n ")
}
str += fmt.Sprintf("%d) %s ", size, pkg.Name())
size++
return nil
})

fmt.Println(str)

for {
fmt.Print("\nEnter a number (default=1): ")

if config.NoConfirm {
fmt.Println()
break
}

reader := bufio.NewReader(os.Stdin)
numberBuf, overflow, err := reader.ReadLine()

if err != nil {
fmt.Println(err)
break
}

if overflow {
fmt.Println("Input too long")
continue
}

if string(numberBuf) == "" {
break
}

num, err := strconv.Atoi(string(numberBuf))
if err != nil {
fmt.Printf("%s invalid number: %s\n", red("error:"), string(numberBuf))
continue
}

if num < 1 || num > size {
fmt.Printf("%s invalid value: %d is not between %d and %d\n", red("error:"), num, 1, size)
continue
}

qp.SetUseIndex(num - 1)
break
}
}

Expand Down
24 changes: 10 additions & 14 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ func removeVCSPackage(pkgs []string) {
updated := false

for _, pkgName := range pkgs {
_, ok := savedInfo[pkgName]
if ok {
if _, ok := savedInfo[pkgName]; ok {
delete(savedInfo, pkgName)
updated = true
}
Expand All @@ -34,10 +33,10 @@ func cleanDependencies(removeOptional bool) error {
}

if len(hanging) != 0 {
err = cleanRemove(hanging)
return cleanRemove(hanging)
}

return err
return nil
}

// CleanRemove sends a full removal command to pacman with the pkgName slice
Expand All @@ -49,8 +48,8 @@ func cleanRemove(pkgNames []string) (err error) {
arguments := makeArguments()
arguments.addArg("R")
arguments.addTarget(pkgNames...)
err = show(passToPacman(arguments))
return err

return show(passToPacman(arguments))
}

func syncClean(parser *arguments) error {
Expand All @@ -69,8 +68,7 @@ func syncClean(parser *arguments) error {
}

if mode == ModeRepo || mode == ModeAny {
err = show(passToPacman(parser))
if err != nil {
if err = show(passToPacman(parser)); err != nil {
return err
}
}
Expand All @@ -86,8 +84,7 @@ func syncClean(parser *arguments) error {
question = "Do you want to remove all other AUR packages from cache?"
}

fmt.Println()
fmt.Printf("Build directory: %s\n", config.BuildDir)
fmt.Printf("\nBuild directory: %s\n", config.BuildDir)

if continueTask(question, true) {
err = cleanAUR(keepInstalled, keepCurrent, removeAll)
Expand All @@ -98,10 +95,10 @@ func syncClean(parser *arguments) error {
}

if continueTask("Do you want to remove ALL untracked AUR files?", true) {
err = cleanUntracked()
return cleanUntracked()
}

return err
return nil
}

func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
Expand Down Expand Up @@ -192,8 +189,7 @@ func cleanUntracked() error {
dir := filepath.Join(config.BuildDir, file.Name())

if shouldUseGit(dir) {
err = show(passToGit(dir, "clean", "-fx"))
if err != nil {
if err = show(passToGit(dir, "clean", "-fx")); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit 0746d28

Please sign in to comment.