mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Resolves #7. Added groundwork for ABS build in install. Updated documentation.
This commit is contained in:
parent
93f008919c
commit
14b46a7461
8 changed files with 103 additions and 98 deletions
|
@ -28,7 +28,11 @@ Yay was created with a few objectives in mind and based on the design of yaourt
|
|||
|
||||
#### 1.100
|
||||
- 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
|
||||
- `--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.
|
||||
func NumberMenu(pkgName string, narrow []string, flags []string) (err error) {
|
||||
var num int
|
||||
var numberString string
|
||||
|
||||
aq, numaq, err := aur.Search(pkgName, true)
|
||||
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.")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
numberString, err = reader.ReadString('\n')
|
||||
if err != nil {
|
||||
numberBuf, overflow, err := reader.ReadLine()
|
||||
if err != nil || overflow {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
numberString := string(numberBuf)
|
||||
var aurInstall []string
|
||||
var repoInstall []string
|
||||
result := strings.Fields(numberString)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
func TestSearch(t *testing.T) {
|
||||
|
||||
eN := "yay"
|
||||
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
||||
result, _, err := Search("yay", true)
|
||||
if err != nil {
|
||||
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)
|
||||
found := false
|
||||
for _, v := range result {
|
||||
if v.Name == eN && v.Description == eD {
|
||||
if v.Name == eN {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +42,6 @@ func BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true,
|
|||
func TestInfo(t *testing.T) {
|
||||
|
||||
eN := "yay"
|
||||
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
||||
eM := []string{"go", "git"}
|
||||
result, _, err := Info("yay")
|
||||
if err != nil {
|
||||
|
@ -53,7 +51,7 @@ func TestInfo(t *testing.T) {
|
|||
// t.Logf("Got struct: %+v", result)
|
||||
found := false
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,28 +11,28 @@ import (
|
|||
|
||||
// Result describes an AUR package.
|
||||
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"`
|
||||
Provides []string `json:"Provides"`
|
||||
License []string `json:"License"`
|
||||
Depends []string `json:"Depends"`
|
||||
Description string `json:"Description"`
|
||||
FirstSubmitted int `json:"FirstSubmitted"`
|
||||
ID int `json:"ID"`
|
||||
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
|
||||
|
@ -112,7 +112,7 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||
}
|
||||
|
||||
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.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) {
|
||||
aurQ.MissingPackage(aurDeps)
|
||||
if !util.ContinueTask("Continue?", "nN") {
|
||||
|
@ -142,7 +142,7 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||
}
|
||||
|
||||
var depArgs []string
|
||||
if util.NoConfirm == true {
|
||||
if util.NoConfirm {
|
||||
depArgs = []string{"--asdeps", "--noconfirm"}
|
||||
} else {
|
||||
depArgs = []string{"--asdeps"}
|
||||
|
@ -172,11 +172,9 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var makepkgcmd *exec.Cmd
|
||||
var args []string
|
||||
args = append(args, "-sri")
|
||||
args := []string{"-sri"}
|
||||
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
|
||||
err = makepkgcmd.Run()
|
||||
return
|
||||
|
|
10
aur/utils.go
10
aur/utils.go
|
@ -3,21 +3,11 @@ package aur
|
|||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// BaseURL givers the AUR default address.
|
||||
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
|
||||
func getJSON(url string, target interface{}) error {
|
||||
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) {
|
||||
if len(os.Args) < 2 {
|
||||
err = fmt.Errorf("no operation specified")
|
||||
return
|
||||
}
|
||||
op = "yogurt"
|
||||
|
||||
for _, arg := range os.Args[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 == "--help" {
|
||||
op = arg
|
||||
} else if arg == "--topdown" {
|
||||
util.SortMode = util.TopDown
|
||||
} else if arg == "--bottomup" {
|
||||
switch arg {
|
||||
case "--build":
|
||||
util.Build = true
|
||||
case "--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
|
||||
options = append(options, arg)
|
||||
} else {
|
||||
fallthrough
|
||||
default:
|
||||
options = append(options, arg)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if arg[0] != '-' {
|
||||
packages = append(packages, arg)
|
||||
}
|
||||
packages = append(packages, arg)
|
||||
}
|
||||
|
||||
if op == "" {
|
||||
op = "yogurt"
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -114,8 +119,6 @@ func main() {
|
|||
if pkgs != nil {
|
||||
err = yay.NumberMenu(pkgs[0], pkgs[1:], options)
|
||||
}
|
||||
case "--help", "-h":
|
||||
usage()
|
||||
default:
|
||||
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
|
||||
func UpdatePackages(flags []string) error {
|
||||
var cmd *exec.Cmd
|
||||
var args []string
|
||||
args := append([]string{"pacman", "-Syu"}, flags...)
|
||||
|
||||
args = append(args, "pacman", "-Syu")
|
||||
args = append(args, flags...)
|
||||
|
||||
cmd = exec.Command("sudo", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd := exec.Command("sudo", args...)
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||
err := cmd.Run()
|
||||
return err
|
||||
}
|
||||
|
@ -85,10 +79,7 @@ func Search(pkgName string) (s Query, n int, err error) {
|
|||
}
|
||||
|
||||
compL := func(len int, i int) bool {
|
||||
if i > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return i > 0
|
||||
}
|
||||
|
||||
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 {
|
||||
if i < len {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return i < len
|
||||
}
|
||||
|
||||
finalL = func(i int) int {
|
||||
|
@ -163,7 +151,7 @@ func (s Query) PrintSearch() {
|
|||
toprint += fmt.Sprintf("(%s) ", res.Group)
|
||||
}
|
||||
|
||||
if res.Installed == true {
|
||||
if res.Installed {
|
||||
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 _, err := dbList.PkgCachebyGroup(pkg); err == nil {
|
||||
if _, errdb := dbList.PkgCachebyGroup(pkg); errdb == nil {
|
||||
repo = append(repo, pkg)
|
||||
} else {
|
||||
aur = append(aur, pkg)
|
||||
|
@ -311,15 +299,11 @@ func Install(pkgName []string, flags []string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
var cmd *exec.Cmd
|
||||
var args []string
|
||||
args = append(args, "pacman", "-S")
|
||||
args := []string{"pacman", "-S"}
|
||||
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.Run()
|
||||
return nil
|
||||
|
@ -331,13 +315,11 @@ func CleanRemove(pkgName []string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
var cmd *exec.Cmd
|
||||
var args []string
|
||||
args = append(args, "pacman", "-Rnsc")
|
||||
args := []string{"pacman", "-Rnsc"}
|
||||
args = append(args, pkgName...)
|
||||
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.Run()
|
||||
return nil
|
||||
|
@ -551,9 +533,9 @@ func GetPkgbuild(pkgN string, path string) (err error) {
|
|||
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)
|
||||
util.DownloadAndUnpack(url, path, true)
|
||||
return nil
|
||||
errD := util.DownloadAndUnpack(url, path, true)
|
||||
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
|
||||
)
|
||||
|
||||
// Build controls if packages will be built from ABS.
|
||||
var Build = false
|
||||
|
||||
// NoConfirm ignores prompts.
|
||||
var NoConfirm = false
|
||||
|
||||
|
@ -116,3 +119,30 @@ func DownloadAndUnpack(url string, path string, trim bool) (err error) {
|
|||
|
||||
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 a new issue