|
@@ -16,33 +16,49 @@ const BuildDir string = "/tmp/yaytmp/"
|
|
|
// SearchMode is search without numbers.
|
|
|
const SearchMode int = -1
|
|
|
|
|
|
-func operation() (operation string, err error) {
|
|
|
+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 {
|
|
|
- return "noop", fmt.Errorf("No operation specified.")
|
|
|
+ err = fmt.Errorf("No operation specified.")
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
for _, arg := range os.Args[1:] {
|
|
|
if arg[0] == '-' && arg[1] != '-' {
|
|
|
- return arg, nil
|
|
|
+ op = arg
|
|
|
+ }
|
|
|
+
|
|
|
+ if arg[0] == '-' && arg[1] == '-' {
|
|
|
+ if arg == "--help" {
|
|
|
+ op = arg
|
|
|
+ }
|
|
|
+ options = append(options, arg)
|
|
|
}
|
|
|
- }
|
|
|
- return "yogurt", nil
|
|
|
-}
|
|
|
|
|
|
-func packages() ([]string, error) {
|
|
|
- var ps []string
|
|
|
- for _, arg := range os.Args[1:] {
|
|
|
if arg[0] != '-' {
|
|
|
- ps = append(ps, arg)
|
|
|
+ packages = append(packages, arg)
|
|
|
}
|
|
|
}
|
|
|
- return ps, nil
|
|
|
-}
|
|
|
|
|
|
-func flags() (fs []string, err error) {
|
|
|
- for _, arg := range os.Args[1:] {
|
|
|
- if arg[0] == '-' && arg[1] == '-' {
|
|
|
- fs = append(fs, arg)
|
|
|
- }
|
|
|
+ if op == "" {
|
|
|
+ op = "yogurt"
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -52,16 +68,12 @@ func main() {
|
|
|
var err error
|
|
|
conf, err := readConfig(PacmanConf)
|
|
|
|
|
|
- op, err := operation()
|
|
|
+ op, pkgs, options, err := parser()
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
|
os.Exit(1)
|
|
|
}
|
|
|
|
|
|
- pkgs, _ := packages()
|
|
|
-
|
|
|
- flag, _ := flags()
|
|
|
-
|
|
|
switch op {
|
|
|
case "-Qstats":
|
|
|
err = stats(&conf)
|
|
@@ -70,15 +82,17 @@ func main() {
|
|
|
err = searchMode(pkg, &conf)
|
|
|
}
|
|
|
case "-S":
|
|
|
- err = InstallPackage(pkgs, &conf, flag)
|
|
|
+ err = InstallPackage(pkgs, &conf, options)
|
|
|
case "-Syu", "-Suy":
|
|
|
- err = updateAndInstall(&conf, flag)
|
|
|
+ err = updateAndInstall(&conf, options)
|
|
|
case "yogurt":
|
|
|
for _, pkg := range pkgs {
|
|
|
- err = searchAndInstall(pkg, &conf, flag)
|
|
|
+ err = searchAndInstall(pkg, &conf, options)
|
|
|
}
|
|
|
+ case "--help", "-h":
|
|
|
+ usage()
|
|
|
default:
|
|
|
- err = passToPacman(op, pkgs, flag)
|
|
|
+ err = passToPacman(op, pkgs, options)
|
|
|
}
|
|
|
|
|
|
if err != nil {
|