mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 17:17:22 +01:00
Resolves #7. Added groundwork for ABS build in install. Updated documentation.
This commit is contained in:
parent
93f008919c
commit
14b46a7461
@ -28,7 +28,11 @@ Yay was created with a few objectives in mind and based on the design of yaourt
|
|||||||
|
|
||||||
#### 1.100
|
#### 1.100
|
||||||
- Added manpage
|
- Added manpage
|
||||||
- Added -G to get pkgbuild from the AUR or ABS.
|
- Improved search [#3](https://github.com/Jguer/yay/issues/3)
|
||||||
|
- Added -G to get pkgbuild from the AUR or ABS. [#6](https://github.com/Jguer/yay/issues/6)
|
||||||
|
- Fixed [#8](https://github.com/Jguer/yay/issues/8)
|
||||||
|
- Completed and decluttered zsh completions
|
||||||
|
- If `$EDITOR` or `$VISUAL` is not set yay will prompt you for an editor [#7](https://github.com/Jguer/yay/issues/7)
|
||||||
|
|
||||||
#### 1.91
|
#### 1.91
|
||||||
- `--downtop` has been replaced with `--bottomup` (as is logical)
|
- `--downtop` has been replaced with `--bottomup` (as is logical)
|
||||||
|
@ -52,7 +52,6 @@ func narrowSearch(aq aur.Query, pq pac.Query, narrow []string) (raq aur.Query, r
|
|||||||
// NumberMenu presents a CLI for selecting packages to install.
|
// NumberMenu presents a CLI for selecting packages to install.
|
||||||
func NumberMenu(pkgName string, narrow []string, flags []string) (err error) {
|
func NumberMenu(pkgName string, narrow []string, flags []string) (err error) {
|
||||||
var num int
|
var num int
|
||||||
var numberString string
|
|
||||||
|
|
||||||
aq, numaq, err := aur.Search(pkgName, true)
|
aq, numaq, err := aur.Search(pkgName, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -83,12 +82,13 @@ func NumberMenu(pkgName string, narrow []string, flags []string) (err error) {
|
|||||||
|
|
||||||
fmt.Printf("\x1b[32m%s\x1b[0m\nNumbers:", "Type numbers to install. Separate each number with a space.")
|
fmt.Printf("\x1b[32m%s\x1b[0m\nNumbers:", "Type numbers to install. Separate each number with a space.")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
numberString, err = reader.ReadString('\n')
|
numberBuf, overflow, err := reader.ReadLine()
|
||||||
if err != nil {
|
if err != nil || overflow {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numberString := string(numberBuf)
|
||||||
var aurInstall []string
|
var aurInstall []string
|
||||||
var repoInstall []string
|
var repoInstall []string
|
||||||
result := strings.Fields(numberString)
|
result := strings.Fields(numberString)
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
func TestSearch(t *testing.T) {
|
func TestSearch(t *testing.T) {
|
||||||
|
|
||||||
eN := "yay"
|
eN := "yay"
|
||||||
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
|
||||||
result, _, err := Search("yay", true)
|
result, _, err := Search("yay", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected err to be nil but it was %s", err)
|
t.Fatalf("Expected err to be nil but it was %s", err)
|
||||||
@ -18,7 +17,7 @@ func TestSearch(t *testing.T) {
|
|||||||
// t.Logf("Got struct: %+v", result)
|
// t.Logf("Got struct: %+v", result)
|
||||||
found := false
|
found := false
|
||||||
for _, v := range result {
|
for _, v := range result {
|
||||||
if v.Name == eN && v.Description == eD {
|
if v.Name == eN {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,7 +42,6 @@ func BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true,
|
|||||||
func TestInfo(t *testing.T) {
|
func TestInfo(t *testing.T) {
|
||||||
|
|
||||||
eN := "yay"
|
eN := "yay"
|
||||||
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
|
||||||
eM := []string{"go", "git"}
|
eM := []string{"go", "git"}
|
||||||
result, _, err := Info("yay")
|
result, _, err := Info("yay")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,7 +51,7 @@ func TestInfo(t *testing.T) {
|
|||||||
// t.Logf("Got struct: %+v", result)
|
// t.Logf("Got struct: %+v", result)
|
||||||
found := false
|
found := false
|
||||||
for _, v := range result {
|
for _, v := range result {
|
||||||
if v.Name == eN && v.Description == eD && reflect.DeepEqual(v.MakeDepends, eM) {
|
if v.Name == eN && reflect.DeepEqual(v.MakeDepends, eM) {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,28 +11,28 @@ import (
|
|||||||
|
|
||||||
// Result describes an AUR package.
|
// Result describes an AUR package.
|
||||||
type Result struct {
|
type Result struct {
|
||||||
ID int `json:"ID"`
|
|
||||||
Name string `json:"Name"`
|
|
||||||
PackageBaseID int `json:"PackageBaseID"`
|
|
||||||
PackageBase string `json:"PackageBase"`
|
|
||||||
Version string `json:"Version"`
|
|
||||||
Description string `json:"Description"`
|
|
||||||
URL string `json:"URL"`
|
|
||||||
NumVotes int `json:"NumVotes"`
|
|
||||||
Popularity float32 `json:"Popularity"`
|
|
||||||
OutOfDate int `json:"OutOfDate"`
|
|
||||||
Maintainer string `json:"Maintainer"`
|
|
||||||
FirstSubmitted int `json:"FirstSubmitted"`
|
|
||||||
LastModified int64 `json:"LastModified"`
|
|
||||||
URLPath string `json:"URLPath"`
|
|
||||||
Installed bool
|
|
||||||
Depends []string `json:"Depends"`
|
|
||||||
MakeDepends []string `json:"MakeDepends"`
|
|
||||||
OptDepends []string `json:"OptDepends"`
|
|
||||||
Conflicts []string `json:"Conflicts"`
|
Conflicts []string `json:"Conflicts"`
|
||||||
Provides []string `json:"Provides"`
|
Depends []string `json:"Depends"`
|
||||||
License []string `json:"License"`
|
Description string `json:"Description"`
|
||||||
|
FirstSubmitted int `json:"FirstSubmitted"`
|
||||||
|
ID int `json:"ID"`
|
||||||
Keywords []string `json:"Keywords"`
|
Keywords []string `json:"Keywords"`
|
||||||
|
LastModified int64 `json:"LastModified"`
|
||||||
|
License []string `json:"License"`
|
||||||
|
Maintainer string `json:"Maintainer"`
|
||||||
|
MakeDepends []string `json:"MakeDepends"`
|
||||||
|
Name string `json:"Name"`
|
||||||
|
NumVotes int `json:"NumVotes"`
|
||||||
|
OptDepends []string `json:"OptDepends"`
|
||||||
|
OutOfDate int `json:"OutOfDate"`
|
||||||
|
PackageBase string `json:"PackageBase"`
|
||||||
|
PackageBaseID int `json:"PackageBaseID"`
|
||||||
|
Provides []string `json:"Provides"`
|
||||||
|
URL string `json:"URL"`
|
||||||
|
URLPath string `json:"URLPath"`
|
||||||
|
Version string `json:"Version"`
|
||||||
|
Installed bool
|
||||||
|
Popularity float32 `json:"Popularity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dependencies returns package dependencies not installed belonging to AUR
|
// Dependencies returns package dependencies not installed belonging to AUR
|
||||||
@ -112,7 +112,7 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !util.ContinueTask("Edit PKGBUILD?", "yY") {
|
if !util.ContinueTask("Edit PKGBUILD?", "yY") {
|
||||||
editcmd := exec.Command(Editor, dir+"PKGBUILD")
|
editcmd := exec.Command(util.Editor(), dir+"PKGBUILD")
|
||||||
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||||
editcmd.Run()
|
editcmd.Run()
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aurQ, n, err := MultiInfo(aurDeps)
|
aurQ, n, _ := MultiInfo(aurDeps)
|
||||||
if n != len(aurDeps) {
|
if n != len(aurDeps) {
|
||||||
aurQ.MissingPackage(aurDeps)
|
aurQ.MissingPackage(aurDeps)
|
||||||
if !util.ContinueTask("Continue?", "nN") {
|
if !util.ContinueTask("Continue?", "nN") {
|
||||||
@ -142,7 +142,7 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var depArgs []string
|
var depArgs []string
|
||||||
if util.NoConfirm == true {
|
if util.NoConfirm {
|
||||||
depArgs = []string{"--asdeps", "--noconfirm"}
|
depArgs = []string{"--asdeps", "--noconfirm"}
|
||||||
} else {
|
} else {
|
||||||
depArgs = []string{"--asdeps"}
|
depArgs = []string{"--asdeps"}
|
||||||
@ -172,11 +172,9 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var makepkgcmd *exec.Cmd
|
args := []string{"-sri"}
|
||||||
var args []string
|
|
||||||
args = append(args, "-sri")
|
|
||||||
args = append(args, flags...)
|
args = append(args, flags...)
|
||||||
makepkgcmd = exec.Command(util.MakepkgBin, args...)
|
makepkgcmd := exec.Command(util.MakepkgBin, args...)
|
||||||
makepkgcmd.Stdin, makepkgcmd.Stdout, makepkgcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
makepkgcmd.Stdin, makepkgcmd.Stdout, makepkgcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||||
err = makepkgcmd.Run()
|
err = makepkgcmd.Run()
|
||||||
return
|
return
|
||||||
|
10
aur/utils.go
10
aur/utils.go
@ -3,21 +3,11 @@ package aur
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// BaseURL givers the AUR default address.
|
// BaseURL givers the AUR default address.
|
||||||
const BaseURL string = "https://aur.archlinux.org"
|
const BaseURL string = "https://aur.archlinux.org"
|
||||||
|
|
||||||
// Editor gives the default system editor, uses vi in last case
|
|
||||||
var Editor = "vi"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if os.Getenv("EDITOR") != "" {
|
|
||||||
Editor = os.Getenv("EDITOR")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getJSON handles JSON retrieval and decoding to struct
|
// getJSON handles JSON retrieval and decoding to struct
|
||||||
func getJSON(url string, target interface{}) error {
|
func getJSON(url string, target interface{}) error {
|
||||||
r, err := http.Get(url)
|
r, err := http.Get(url)
|
||||||
|
@ -33,43 +33,48 @@ func usage() {
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = "1.92"
|
var version = "1.100"
|
||||||
|
|
||||||
func parser() (op string, options []string, packages []string, err error) {
|
func parser() (op string, options []string, packages []string, err error) {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
err = fmt.Errorf("no operation specified")
|
err = fmt.Errorf("no operation specified")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
op = "yogurt"
|
||||||
|
|
||||||
for _, arg := range os.Args[1:] {
|
for _, arg := range os.Args[1:] {
|
||||||
if arg[0] == '-' && arg[1] != '-' {
|
if arg[0] == '-' && arg[1] != '-' {
|
||||||
op = arg
|
switch arg {
|
||||||
|
case "-b":
|
||||||
|
util.Build = true
|
||||||
|
default:
|
||||||
|
op = arg
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg[0] == '-' && arg[1] == '-' {
|
if arg[0] == '-' && arg[1] == '-' {
|
||||||
if arg == "--help" {
|
switch arg {
|
||||||
op = arg
|
case "--build":
|
||||||
} else if arg == "--topdown" {
|
util.Build = true
|
||||||
util.SortMode = util.TopDown
|
case "--bottomup":
|
||||||
} else if arg == "--bottomup" {
|
|
||||||
util.SortMode = util.BottomUp
|
util.SortMode = util.BottomUp
|
||||||
} else if arg == "--noconfirm" {
|
case "--topdown":
|
||||||
|
util.SortMode = util.TopDown
|
||||||
|
case "--help":
|
||||||
|
usage()
|
||||||
|
os.Exit(0)
|
||||||
|
case "--noconfirm":
|
||||||
util.NoConfirm = true
|
util.NoConfirm = true
|
||||||
options = append(options, arg)
|
fallthrough
|
||||||
} else {
|
default:
|
||||||
options = append(options, arg)
|
options = append(options, arg)
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg[0] != '-' {
|
packages = append(packages, arg)
|
||||||
packages = append(packages, arg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if op == "" {
|
|
||||||
op = "yogurt"
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +119,6 @@ func main() {
|
|||||||
if pkgs != nil {
|
if pkgs != nil {
|
||||||
err = yay.NumberMenu(pkgs[0], pkgs[1:], options)
|
err = yay.NumberMenu(pkgs[0], pkgs[1:], options)
|
||||||
}
|
}
|
||||||
case "--help", "-h":
|
|
||||||
usage()
|
|
||||||
default:
|
default:
|
||||||
err = yay.PassToPacman(op, pkgs, options)
|
err = yay.PassToPacman(op, pkgs, options)
|
||||||
}
|
}
|
||||||
|
@ -46,16 +46,10 @@ func readConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
|||||||
|
|
||||||
// UpdatePackages handles cache update and upgrade
|
// UpdatePackages handles cache update and upgrade
|
||||||
func UpdatePackages(flags []string) error {
|
func UpdatePackages(flags []string) error {
|
||||||
var cmd *exec.Cmd
|
args := append([]string{"pacman", "-Syu"}, flags...)
|
||||||
var args []string
|
|
||||||
|
|
||||||
args = append(args, "pacman", "-Syu")
|
cmd := exec.Command("sudo", args...)
|
||||||
args = append(args, flags...)
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||||
|
|
||||||
cmd = exec.Command("sudo", args...)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -85,10 +79,7 @@ func Search(pkgName string) (s Query, n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compL := func(len int, i int) bool {
|
compL := func(len int, i int) bool {
|
||||||
if i > 0 {
|
return i > 0
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
finalL := func(i int) int {
|
finalL := func(i int) int {
|
||||||
@ -102,10 +93,7 @@ func Search(pkgName string) (s Query, n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compL = func(len int, i int) bool {
|
compL = func(len int, i int) bool {
|
||||||
if i < len {
|
return i < len
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
finalL = func(i int) int {
|
finalL = func(i int) int {
|
||||||
@ -163,7 +151,7 @@ func (s Query) PrintSearch() {
|
|||||||
toprint += fmt.Sprintf("(%s) ", res.Group)
|
toprint += fmt.Sprintf("(%s) ", res.Group)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Installed == true {
|
if res.Installed {
|
||||||
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +204,7 @@ func PackageSlices(toCheck []string) (aur []string, repo []string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
if _, err := dbList.PkgCachebyGroup(pkg); err == nil {
|
if _, errdb := dbList.PkgCachebyGroup(pkg); errdb == nil {
|
||||||
repo = append(repo, pkg)
|
repo = append(repo, pkg)
|
||||||
} else {
|
} else {
|
||||||
aur = append(aur, pkg)
|
aur = append(aur, pkg)
|
||||||
@ -311,15 +299,11 @@ func Install(pkgName []string, flags []string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
args := []string{"pacman", "-S"}
|
||||||
var args []string
|
|
||||||
args = append(args, "pacman", "-S")
|
|
||||||
args = append(args, pkgName...)
|
args = append(args, pkgName...)
|
||||||
if len(flags) != 0 {
|
args = append(args, flags...)
|
||||||
args = append(args, flags...)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = exec.Command("sudo", args...)
|
cmd := exec.Command("sudo", args...)
|
||||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
return nil
|
return nil
|
||||||
@ -331,13 +315,11 @@ func CleanRemove(pkgName []string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
args := []string{"pacman", "-Rnsc"}
|
||||||
var args []string
|
|
||||||
args = append(args, "pacman", "-Rnsc")
|
|
||||||
args = append(args, pkgName...)
|
args = append(args, pkgName...)
|
||||||
args = append(args, "--noconfirm")
|
args = append(args, "--noconfirm")
|
||||||
|
|
||||||
cmd = exec.Command("sudo", args...)
|
cmd := exec.Command("sudo", args...)
|
||||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
return nil
|
return nil
|
||||||
@ -551,9 +533,9 @@ func GetPkgbuild(pkgN string, path string) (err error) {
|
|||||||
return fmt.Errorf("Not in standard repositories")
|
return fmt.Errorf("Not in standard repositories")
|
||||||
}
|
}
|
||||||
fmt.Printf("\x1b[1;32m==>\x1b[1;33m %s \x1b[1;32mfound in ABS.\x1b[0m\n", pkgN)
|
fmt.Printf("\x1b[1;32m==>\x1b[1;33m %s \x1b[1;32mfound in ABS.\x1b[0m\n", pkgN)
|
||||||
util.DownloadAndUnpack(url, path, true)
|
errD := util.DownloadAndUnpack(url, path, true)
|
||||||
return nil
|
return errD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Package not found.")
|
return fmt.Errorf("package not found")
|
||||||
}
|
}
|
||||||
|
30
util/util.go
30
util/util.go
@ -25,6 +25,9 @@ const (
|
|||||||
Minimal
|
Minimal
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Build controls if packages will be built from ABS.
|
||||||
|
var Build = false
|
||||||
|
|
||||||
// NoConfirm ignores prompts.
|
// NoConfirm ignores prompts.
|
||||||
var NoConfirm = false
|
var NoConfirm = false
|
||||||
|
|
||||||
@ -116,3 +119,30 @@ func DownloadAndUnpack(url string, path string, trim bool) (err error) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Editor returns the prefered system editor.
|
||||||
|
func Editor() string {
|
||||||
|
if os.Getenv("EDITOR") != "" {
|
||||||
|
return os.Getenv("EDITOR")
|
||||||
|
} else if os.Getenv("VISUAL") != "" {
|
||||||
|
return os.Getenv("VISUAL")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m$EDITOR\x1b[0;;40m is not set.\x1b[0m\nPlease add $EDITOR or to your environment variables.\n")
|
||||||
|
|
||||||
|
editorLoop:
|
||||||
|
fmt.Printf("\x1b[32m%s\x1b[0m ", "Edit PKGBUILD with:")
|
||||||
|
var editorInput string
|
||||||
|
_, err := fmt.Scanln(&editorInput)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
goto editorLoop
|
||||||
|
}
|
||||||
|
|
||||||
|
editor, err := exec.LookPath(editorInput)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
goto editorLoop
|
||||||
|
}
|
||||||
|
return editor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user