Skip to content

Commit

Permalink
Resolves #7. Added groundwork for ABS build in install. Updated docum…
Browse files Browse the repository at this point in the history
…entation.
  • Loading branch information
Jguer committed Feb 17, 2017
1 parent 93f0089 commit 14b46a7
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 96 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions aur/aur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand Down
48 changes: 23 additions & 25 deletions aur/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Conflicts []string `json:"Conflicts"`
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"`
Conflicts []string `json:"Conflicts"`
OutOfDate int `json:"OutOfDate"`
PackageBase string `json:"PackageBase"`
PackageBaseID int `json:"PackageBaseID"`
Provides []string `json:"Provides"`
License []string `json:"License"`
Keywords []string `json:"Keywords"`
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
Expand Down Expand Up @@ -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()
}
Expand All @@ -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") {
Expand All @@ -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"}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions aur/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 23 additions & 20 deletions cmd/yay/yay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down
48 changes: 15 additions & 33 deletions pacman/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
Loading

0 comments on commit 14b46a7

Please sign in to comment.