mirror of
https://github.com/Jguer/yay
synced 2024-08-31 05:39:29 +00:00
Bold text, refactoring and AUR dependency grabbing
This commit is contained in:
parent
bf0c6e4692
commit
bacd56083b
57
aur.go
57
aur.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -90,25 +91,24 @@ func (r AurSearch) Swap(i, j int) {
|
|||
r.Results[i], r.Results[j] = r.Results[j], r.Results[i]
|
||||
}
|
||||
|
||||
func searchAurPackages(pkg string) (search AurSearch) {
|
||||
getJSON("https://aur.archlinux.org/rpc/?v=5&type=search&arg="+pkg, &search)
|
||||
func searchAurPackages(pkg string) (search AurSearch, err error) {
|
||||
err = getJSON("https://aur.archlinux.org/rpc/?v=5&type=search&arg="+pkg, &search)
|
||||
sort.Sort(search)
|
||||
return search
|
||||
return
|
||||
}
|
||||
|
||||
func infoAurPackage(pkg string) (info AurInfo) {
|
||||
fmt.Println("https://aur.archlinux.org/rpc/?v=5&type=info&arg[]=" + pkg)
|
||||
getJSON("https://aur.archlinux.org/rpc/?v=5&type=info&arg[]="+pkg, &info)
|
||||
return info
|
||||
func infoAurPackage(pkg string) (info AurInfo, err error) {
|
||||
err = getJSON("https://aur.archlinux.org/rpc/?v=5&type=info&arg[]="+pkg, &info)
|
||||
return
|
||||
}
|
||||
|
||||
func (r AurSearch) printSearch(index int) (err error) {
|
||||
for i, result := range r.Results {
|
||||
if index != SearchMode {
|
||||
fmt.Printf("%d aur/\x1B[33m%s\033[0m \x1B[36m%s\033[0m (%d)\n %s\n",
|
||||
fmt.Printf("%d \033[1maur/\x1B[33m%s \x1B[36m%s\033[0m (%d)\n %s\n",
|
||||
i+index, result.Name, result.Version, result.NumVotes, result.Description)
|
||||
} else {
|
||||
fmt.Printf("aur/\x1B[33m%s\033[0m \x1B[36m%s\033[0m (%d)\n %s\n",
|
||||
fmt.Printf("\033[1maur/\x1B[33m%s \x1B[36m%s\033[0m (%d)\n %s\n",
|
||||
result.Name, result.Version, result.NumVotes, result.Description)
|
||||
}
|
||||
}
|
||||
|
@ -116,23 +116,6 @@ func (r AurSearch) printSearch(index int) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (r AurSearch) installAurArray(num []int, index int) (err error) {
|
||||
if len(num) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, i := range num {
|
||||
fmt.Printf("%+v\n\n", r.Results[i-index])
|
||||
err = r.Results[i-index].installResult()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func downloadFile(filepath string, url string) (err error) {
|
||||
// Create the file
|
||||
out, err := os.Create(filepath)
|
||||
|
@ -185,29 +168,35 @@ func (a AurResult) getDepsfromFile(pkgbuildLoc string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a AurResult) getDepsFromRPC() (err error) {
|
||||
info := infoAurPackage(a.Name)
|
||||
fmt.Printf("%+v\n", info)
|
||||
|
||||
func (a AurResult) getDepsFromRPC() (final []string, err error) {
|
||||
f := func(c rune) bool {
|
||||
return c == '>' || c == '<' || c == '=' || c == ' '
|
||||
}
|
||||
info, err := infoAurPackage(a.Name)
|
||||
|
||||
if len(info.Results) == 0 {
|
||||
return final, errors.New("Failed to get deps from RPC")
|
||||
}
|
||||
|
||||
for _, deps := range info.Results[0].MakeDepends {
|
||||
fields := strings.FieldsFunc(deps, f)
|
||||
fmt.Println(fields[0])
|
||||
if !isInRepo(fields[0]) {
|
||||
final = append(final, fields[0])
|
||||
}
|
||||
}
|
||||
|
||||
for _, deps := range info.Results[0].Depends {
|
||||
fields := strings.FieldsFunc(deps, f)
|
||||
fmt.Println(fields[0])
|
||||
if !isInRepo(fields[0]) {
|
||||
final = append(final, fields[0])
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a AurResult) getAURDependencies() (err error) {
|
||||
a.getDepsFromRPC()
|
||||
_, err = a.getDepsFromRPC()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -244,7 +233,7 @@ func (a AurResult) installResult() (err error) {
|
|||
a.getAURDependencies()
|
||||
os.Exit(0)
|
||||
|
||||
fmt.Print("==> Edit PKGBUILD? (y/n)")
|
||||
fmt.Print("\x1b[32m==> Edit PKGBUILD? (y/n)\033[0m")
|
||||
var response string
|
||||
fmt.Scanln(&response)
|
||||
if strings.ContainsAny(response, "y & Y") {
|
||||
|
|
22
repo.go
22
repo.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
c "github.com/fatih/color"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -33,12 +32,9 @@ func getInstalledPackage(pkg string) (err error) {
|
|||
// SearchPackages handles repo searches
|
||||
func SearchPackages(pkg string) (search RepoSearch, err error) {
|
||||
cmdOutput, err := exec.Command(PacmanBin, "-Ss", pkg).Output()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
outputSlice := strings.Split(string(cmdOutput), "\n")
|
||||
if outputSlice[0] == "" {
|
||||
return
|
||||
return search, nil
|
||||
}
|
||||
|
||||
i := true
|
||||
|
@ -62,17 +58,23 @@ func SearchPackages(pkg string) (search RepoSearch, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func isInRepo(pkg string) bool {
|
||||
if _, err := exec.Command(PacmanBin, "-Sp", pkg).Output(); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s RepoSearch) printSearch(index int) (err error) {
|
||||
yellow := c.New(c.FgYellow).SprintFunc()
|
||||
green := c.New(c.FgGreen).SprintFunc()
|
||||
|
||||
for i, result := range s.Results {
|
||||
if index != SearchMode {
|
||||
fmt.Printf("%d %s/\x1B[33m%s\033[0m \x1B[36m%s\033[0m\n%s\n",
|
||||
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
||||
i, result.Repository, result.Name, result.Version, result.Description)
|
||||
} else {
|
||||
fmt.Printf("%s/\x1B[33m%s\033[0m \x1B[36m%s\033[0m\n%s\n",
|
||||
result.Repository, yellow(result.Name), green(result.Version), result.Description)
|
||||
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
||||
result.Repository, result.Name, result.Version, result.Description)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
50
yay.go
50
yay.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -55,22 +56,51 @@ func getNums() (numbers []int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func defaultMode(pkg string) {
|
||||
aurRes := searchAurPackages(pkg)
|
||||
func installnumArray(num []int, aurRes AurSearch, repoRes RepoSearch) (err error) {
|
||||
if len(num) == 0 {
|
||||
return errors.New("Installing AUR array: No nums selected")
|
||||
}
|
||||
|
||||
var index int
|
||||
for _, i := range num {
|
||||
if i > repoRes.Resultcount-1 {
|
||||
index = i - repoRes.Resultcount
|
||||
fmt.Printf("%+v\n\n", aurRes.Results[i-index])
|
||||
err = aurRes.Results[i-index].installResult()
|
||||
if err != nil {
|
||||
// Do not abandon program, we might still be able to install the rest
|
||||
fmt.Println(err)
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func defaultMode(pkg string) (err error) {
|
||||
aurRes, err := searchAurPackages(pkg)
|
||||
repoRes, err := SearchPackages(pkg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if repoRes.Resultcount == 0 && aurRes.Resultcount == 0 {
|
||||
os.Exit(1)
|
||||
return errors.New("No Packages match search")
|
||||
}
|
||||
repoRes.printSearch(0)
|
||||
err = aurRes.printSearch(repoRes.Resultcount)
|
||||
|
||||
nums, err := getNums()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
aurRes.installAurArray(nums, repoRes.Resultcount)
|
||||
|
||||
err = installnumArray(nums, aurRes, repoRes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -79,5 +109,9 @@ func main() {
|
|||
Editor = os.Getenv("EDITOR")
|
||||
}
|
||||
searchTerm := flag.Args()
|
||||
defaultMode(searchTerm[0])
|
||||
err := defaultMode(searchTerm[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue