yay/yay.go

89 lines
1.5 KiB
Go
Raw Normal View History

2016-09-05 02:17:51 +00:00
package main
import (
"fmt"
"os"
)
var version string
2016-09-13 01:06:24 +00:00
// PacmanConf describes the default pacman config file
const PacmanConf string = "/etc/pacman.conf"
2016-09-06 21:22:20 +00:00
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
// SearchMode is search without numbers.
const SearchMode int = -1
func operation() (operation string, err error) {
if len(os.Args) < 2 {
return "noop", fmt.Errorf("No operation specified.")
}
for _, arg := range os.Args[1:] {
if arg[0] == '-' && arg[1] != '-' {
return arg, nil
}
}
return "yogurt", nil
}
2016-10-02 20:50:23 +00:00
func packages() ([]string, error) {
var ps []string
for _, arg := range os.Args[1:] {
if arg[0] != '-' {
ps = append(ps, arg)
}
}
2016-10-02 20:50:23 +00:00
return ps, nil
}
func flags() (fs []string, err error) {
for _, arg := range os.Args[1:] {
if arg[0] == '-' && arg[1] == '-' {
fs = append(fs, arg)
}
}
return
}
2016-09-05 02:17:51 +00:00
func main() {
2016-09-09 13:55:16 +00:00
var err error
2016-09-13 01:06:24 +00:00
conf, err := readConfig(PacmanConf)
op, err := operation()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2016-10-02 20:50:23 +00:00
pkgs, _ := packages()
flag, _ := flags()
2016-09-10 23:02:53 +00:00
switch op {
case "-Qstats":
err = stats(&conf)
case "-Ss":
2016-10-02 20:50:23 +00:00
for _, pkg := range pkgs {
err = searchMode(pkg, &conf)
}
case "-S":
2016-10-02 20:50:23 +00:00
err = InstallPackage(pkgs, &conf, flag)
case "-Syu":
err = updateAndInstall(&conf, flag)
case "yogurt":
2016-10-02 20:50:23 +00:00
for _, pkg := range pkgs {
err = searchAndInstall(pkg, &conf, flag)
}
default:
err = passToPacman(op, pkgs, flag)
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
}