Adding alternative search method

This commit is contained in:
Jguer 2016-09-11 00:02:53 +01:00
parent 143764cf20
commit 68fa4d8286
4 changed files with 69 additions and 25 deletions

View File

@ -98,17 +98,21 @@ func (a AurResult) install(flags ...string) (err error) {
return
}
// InstallPackage handles repo installs
// InstallPackage handles package install
func InstallPackage(pkg string, flags ...string) (err error) {
var args string
fmt.Println(len(flags))
if len(flags) != 0 {
args = fmt.Sprintf(" %s", strings.Join(flags, " "))
if isInRepo(pkg) {
var args string
if len(flags) != 0 {
args = fmt.Sprintf(" %s", strings.Join(flags, " "))
}
cmd := exec.Command("sudo", "pacman", "-S", pkg+args)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err = cmd.Run()
} else {
err = installAURPackage(os.Args[2], os.Args[3:]...)
}
cmd := exec.Command("sudo", "pacman", "-S", pkg+args)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err = cmd.Run()
return nil
}

View File

@ -5,9 +5,20 @@ import (
"os"
)
type operation struct {
key byte
description string
modifiers []modifier
execute func()
}
type modifier struct {
description string
}
// ReturnArgs prints os args
func ReturnArgs() {
for o := range os.Args {
for _, o := range os.Args {
fmt.Println(o)
}
}

View File

@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"github.com/Jguer/go-alpm"
"os"
"os/exec"
"sort"
@ -20,6 +21,43 @@ func searchAurPackages(pkg string, index int) (search AurSearch, err error) {
// SearchPackages handles repo searches
func SearchPackages(pkg string) (search RepoSearch, err error) {
h, er := alpm.Init("/", "/var/lib/pacman")
if er != nil {
fmt.Println(er)
return
}
defer h.Release()
fmt.Println("before dblist")
dbList, _ := h.SyncDbs()
fmt.Println("after dblist")
// db, _ := h.RegisterSyncDb("core", 0)
// h.RegisterSyncDb("community", 0)
// h.RegisterSyncDb("extra", 0)
_, err = h.SyncDbByName("core")
fmt.Println(err)
fmt.Printf("%+v\n", dbList)
db, _ := h.LocalDb()
for _, pkg := range db.PkgCache().Slice() {
fmt.Printf("%s %s\n %s\n",
pkg.Name(), pkg.Version(), pkg.Description())
}
for _, db := range dbList.Slice() {
fmt.Printf("%+v\n", db)
db, _ := h.LocalDb()
for _, pkg := range db.PkgCache().Slice() {
fmt.Printf("%s %s\n %s\n",
pkg.Name(), pkg.Version(), pkg.Description())
}
}
return
}
// SearchPackagesa handles repo searches
func SearchPackagesa(pkg string) (search RepoSearch, err error) {
cmdOutput, err := exec.Command(PacmanBin, "-Ss", pkg).Output()
outputSlice := strings.Split(string(cmdOutput), "\n")
if outputSlice[0] == "" {
@ -161,5 +199,3 @@ func getInstalledPackage(pkg string) (err error) {
err = cmd.Run()
return
}

17
yay.go
View File

@ -3,7 +3,6 @@ package main
import (
"bufio"
"errors"
"flag"
"fmt"
"os"
"strconv"
@ -94,23 +93,17 @@ func searchMode(pkg string) (err error) {
}
func main() {
flag.Parse()
var err error
if os.Getenv("EDITOR") != "" {
Editor = os.Getenv("EDITOR")
}
args := flag.Args()
if args[0] == "-Ss" {
err = searchMode(strings.Join(args[2:], " "))
if os.Args[1] == "-Ss" {
err = searchMode(strings.Join(os.Args[3:], " "))
} else if args[0] == "-S" {
if isInRepo(args[1]) {
err = InstallPackage(args[1], args[2:]...)
} else {
err = installAURPackage(args[1], args[2:]...)
}
} else if os.Args[1] == "-S" {
err = InstallPackage(os.Args[2], os.Args[3:]...)
} else {
err = defaultMode(args[0])
err = defaultMode(os.Args[1])
}
if err != nil {