Browse Source

Added yay cmd

Jguer 8 years ago
parent
commit
517939d108
2 changed files with 92 additions and 1 deletions
  1. 0 1
      .gitignore
  2. 92 0
      cmd/yay/yay.go

+ 0 - 1
.gitignore

@@ -26,4 +26,3 @@ _testmain.go
 # Output of the go coverage tool, specifically when used with LiteIDE
 *.out
 bin/yay
-yay

+ 92 - 0
cmd/yay/yay.go

@@ -0,0 +1,92 @@
+package main
+
+import (
+	"fmt"
+	"os"
+
+	"github.com/jguer/yay"
+)
+
+func usage() {
+	fmt.Println(`usage:  yay <operation> [...]
+    operations:
+    yay {-h --help}
+    yay {-V --version}
+    yay {-D --database} <options> <package(s)>
+    yay {-F --files}    [options] [package(s)]
+    yay {-Q --query}    [options] [package(s)]
+    yay {-R --remove}   [options] <package(s)>
+    yay {-S --sync}     [options] [package(s)]
+    yay {-T --deptest}  [options] [package(s)]
+    yay {-U --upgrade}  [options] <file(s)>
+
+    New operations:
+    yay -Qstats  -  Displays system information
+`)
+}
+
+func parser() (op string, options []string, packages []string, err error) {
+	if len(os.Args) < 2 {
+		err = fmt.Errorf("no operation specified")
+		return
+	}
+
+	for _, arg := range os.Args[1:] {
+		if arg[0] == '-' && arg[1] != '-' {
+			op = arg
+		}
+
+		if arg[0] == '-' && arg[1] == '-' {
+			if arg == "--help" {
+				op = arg
+			}
+			options = append(options, arg)
+		}
+
+		if arg[0] != '-' {
+			packages = append(packages, arg)
+		}
+	}
+
+	if op == "" {
+		op = "yogurt"
+	}
+
+	return
+}
+
+func main() {
+
+	op, options, pkgs, err := parser()
+	if err != nil {
+		fmt.Println(err)
+		os.Exit(1)
+	}
+
+	switch op {
+	case "-Qstats":
+		err = yay.LocalStatistics()
+	case "-Ss":
+		for _, pkg := range pkgs {
+			err = searchMode(pkg, &conf)
+		}
+	case "-S":
+		err = InstallPackage(pkgs, &conf, options)
+	case "-Syu", "-Suy":
+		err = yay.Upgrade(options)
+	case "yogurt":
+		for _, pkg := range pkgs {
+			err = yay.NumberMenu(pkg, &conf, options)
+			break
+		}
+	case "--help", "-h":
+		usage()
+	default:
+		err = passToPacman(op, pkgs, options)
+	}
+
+	if err != nil {
+		fmt.Println(err)
+		os.Exit(1)
+	}
+}