yay/yay.go

114 lines
2.3 KiB
Go
Raw Normal View History

2016-09-05 02:17:51 +00:00
package main
import (
"bufio"
"errors"
2016-09-05 02:17:51 +00:00
"fmt"
"os"
"strconv"
"strings"
)
// PacmanBin describes the default installation point of pacman
const PacmanBin string = "/usr/bin/pacman"
2016-09-06 21:22:20 +00:00
// MakepkgBin describes the default installation point of makepkg command
const MakepkgBin string = "/usr/bin/makepkg"
// TarBin describes the default installation point of tar command
// Probably will replace untar with code solution
const TarBin string = "/usr/bin/tar"
2016-09-05 02:17:51 +00:00
// SearchMode is search without numbers
const SearchMode int = -1
2016-09-05 22:47:36 +00:00
// BuildDir is the root for package building
2016-09-06 21:22:20 +00:00
const BuildDir string = "/tmp/yaytmp/"
2016-09-05 22:47:36 +00:00
// BaseURL givers the AUR default address
const BaseURL string = "https://aur.archlinux.org"
2016-09-06 21:22:20 +00:00
// Editor gives the default system editor, uses vi in last case
var Editor = "vi"
2016-09-05 02:17:51 +00:00
func getNums() (numbers []int, err error) {
var numberString string
2016-09-05 22:47:36 +00:00
fmt.Printf("\x1B[32m%s\033[0m\nNumbers:", "Type numbers to install. Separate each number with a space.")
2016-09-05 02:17:51 +00:00
reader := bufio.NewReader(os.Stdin)
numberString, err = reader.ReadString('\n')
if err != nil {
fmt.Println(err)
return
}
result := strings.Fields(numberString)
var num int
for _, numS := range result {
num, err = strconv.Atoi(numS)
if err != nil {
fmt.Println(err)
return
}
numbers = append(numbers, num)
}
return
}
func defaultMode(pkg string) (err error) {
2016-09-09 13:55:16 +00:00
aurRes, err := searchAurPackages(pkg, 0)
2016-09-05 02:17:51 +00:00
repoRes, err := SearchPackages(pkg)
if err != nil {
return
}
2016-09-05 22:47:36 +00:00
if repoRes.Resultcount == 0 && aurRes.Resultcount == 0 {
return errors.New("No Packages match search")
2016-09-05 22:47:36 +00:00
}
2016-09-05 02:17:51 +00:00
repoRes.printSearch(0)
err = aurRes.printSearch(repoRes.Resultcount)
2016-09-05 22:47:36 +00:00
2016-09-05 02:17:51 +00:00
nums, err := getNums()
if err != nil {
return
2016-09-05 02:17:51 +00:00
}
err = installnumArray(nums, aurRes, repoRes)
if err != nil {
return
}
return
2016-09-05 02:17:51 +00:00
}
2016-09-09 13:55:16 +00:00
func searchMode(pkg string) (err error) {
aur, err := searchAurPackages(pkg, SearchMode)
repo, err := SearchPackages(pkg)
if err != nil {
return err
}
aur.printSearch(SearchMode)
repo.printSearch(SearchMode)
return nil
}
2016-09-05 02:17:51 +00:00
func main() {
2016-09-09 13:55:16 +00:00
var err error
2016-09-06 21:22:20 +00:00
if os.Getenv("EDITOR") != "" {
Editor = os.Getenv("EDITOR")
}
2016-09-10 23:02:53 +00:00
if os.Args[1] == "-Ss" {
err = searchMode(strings.Join(os.Args[3:], " "))
} else if os.Args[1] == "-S" {
err = InstallPackage(os.Args[2], os.Args[3:]...)
2016-09-09 13:55:16 +00:00
} else {
2016-09-10 23:02:53 +00:00
err = defaultMode(os.Args[1])
2016-09-09 13:55:16 +00:00
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2016-09-05 02:17:51 +00:00
}