2018-03-16 01:18:13 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-03-16 20:30:14 +01:00
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2018-04-16 14:26:15 +02:00
|
|
|
|
|
|
|
alpm "github.com/jguer/go-alpm"
|
2018-03-16 01:18:13 +01:00
|
|
|
)
|
|
|
|
|
2018-03-19 16:30:44 +01:00
|
|
|
func questionCallback(question alpm.QuestionAny) {
|
2018-07-31 10:42:17 +02:00
|
|
|
if qi, err := question.QuestionInstallIgnorepkg(); err == nil {
|
2018-03-16 20:30:14 +01:00
|
|
|
qi.SetInstall(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
qp, err := question.QuestionSelectProvider()
|
2018-07-31 10:42:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:05:45 +02:00
|
|
|
if hideMenus {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-31 10:42:17 +02:00
|
|
|
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()
|
2018-03-16 20:30:14 +01:00
|
|
|
break
|
|
|
|
}
|
2018-07-31 10:42:17 +02:00
|
|
|
|
|
|
|
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
|
2018-03-16 01:18:13 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-26 14:35:19 +02:00
|
|
|
|
|
|
|
func logCallback(level alpm.LogLevel, str string) {
|
|
|
|
switch level {
|
|
|
|
case alpm.LogWarning:
|
|
|
|
fmt.Print(bold(yellow(smallArrow)), " ", str)
|
|
|
|
case alpm.LogError:
|
|
|
|
fmt.Print(bold(red(smallArrow)), " ", str)
|
|
|
|
}
|
|
|
|
}
|