Fixed pacman pass prepend

This commit is contained in:
Jguer 2016-10-02 18:52:48 +01:00
parent 5b60bb6781
commit 1a77f42276
3 changed files with 16 additions and 12 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"github.com/Jguer/go-alpm"
@ -14,6 +15,7 @@ import (
func searchAndInstall(pkgName string, conf *alpm.PacmanConfig, flags string) (err error) {
var num int
var numberString string
var pacBuffer bytes.Buffer
a, err := aur.Search(pkgName, true)
r, err := SearchPackages(pkgName, conf)
@ -35,7 +37,7 @@ func searchAndInstall(pkgName string, conf *alpm.PacmanConfig, flags string) (er
return
}
var index int
var aurInstall []aur.Result
result := strings.Fields(numberString)
for _, numS := range result {
num, err = strconv.Atoi(numS)
@ -46,17 +48,22 @@ func searchAndInstall(pkgName string, conf *alpm.PacmanConfig, flags string) (er
// Install package
if num > len(r.Results)-1 {
index = num - len(r.Results)
err = a.Results[index].Install(BuildDir, conf, flags)
if err != nil {
// Do not abandon program, we might still be able to install the rest
fmt.Println(err)
}
aurInstall = append(aurInstall, a.Results[num-len(r.Results)])
} else {
InstallPackage(r.Results[num].Name, conf, flags)
pacBuffer.WriteString(r.Results[num].Name)
pacBuffer.WriteString(" ")
}
}
InstallPackage(strings.TrimSpace(pacBuffer.String()), conf, flags)
for _, aurpkg := range aurInstall {
err = aurpkg.Install(BuildDir, conf, flags)
if err != nil {
// Do not abandon program, we might still be able to install the rest
fmt.Println(err)
}
}
return
}

View file

@ -143,7 +143,7 @@ func passToPacman(op string, pkg string, flags string) error {
if strings.Contains(op, "Q") {
cmd = exec.Command("pacman", args...)
} else {
args = append(args, "pacman")
args = append([]string{"pacman"}, args...)
cmd = exec.Command("sudo", args...)
}

3
yay.go
View file

@ -7,9 +7,6 @@ import (
"strings"
)
// PacmanBin describes the default installation point of pacman
const PacmanBin string = "/usr/bin/pacman"
// PacmanConf describes the default pacman config file
const PacmanConf string = "/etc/pacman.conf"