yay.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/jguer/yay"
  6. )
  7. func usage() {
  8. fmt.Println(`usage: yay <operation> [...]
  9. operations:
  10. yay {-h --help}
  11. yay {-V --version}
  12. yay {-D --database} <options> <package(s)>
  13. yay {-F --files} [options] [package(s)]
  14. yay {-Q --query} [options] [package(s)]
  15. yay {-R --remove} [options] <package(s)>
  16. yay {-S --sync} [options] [package(s)]
  17. yay {-T --deptest} [options] [package(s)]
  18. yay {-U --upgrade} [options] <file(s)>
  19. New operations:
  20. yay -Qstats displays system information
  21. New options:
  22. --topdown shows repository's packages first and then aur's
  23. --downtop shows aur's packages first and then repository's
  24. --noconfirm skip user input on package install
  25. `)
  26. }
  27. var version = "1.82"
  28. func parser() (op string, options []string, packages []string, err error) {
  29. if len(os.Args) < 2 {
  30. err = fmt.Errorf("no operation specified")
  31. return
  32. }
  33. for _, arg := range os.Args[1:] {
  34. if arg[0] == '-' && arg[1] != '-' {
  35. op = arg
  36. }
  37. if arg[0] == '-' && arg[1] == '-' {
  38. if arg == "--help" {
  39. op = arg
  40. } else if arg == "--topdown" {
  41. yay.SortMode = yay.TopDown
  42. } else if arg == "--downtop" {
  43. yay.SortMode = yay.DownTop
  44. } else if arg == "--noconfirm" {
  45. yay.NoConfirm = true
  46. options = append(options, arg)
  47. } else {
  48. options = append(options, arg)
  49. }
  50. }
  51. if arg[0] != '-' {
  52. packages = append(packages, arg)
  53. }
  54. }
  55. if op == "" {
  56. op = "yogurt"
  57. }
  58. return
  59. }
  60. func main() {
  61. op, options, pkgs, err := parser()
  62. if err != nil {
  63. fmt.Println(err)
  64. os.Exit(1)
  65. }
  66. yay.Config()
  67. switch op {
  68. case "-Cd":
  69. err = yay.CleanDependencies(pkgs)
  70. case "-Qstats":
  71. err = yay.LocalStatistics(version)
  72. case "-Ss":
  73. for _, pkg := range pkgs {
  74. err = yay.Search(pkg)
  75. }
  76. case "-S":
  77. err = yay.Install(pkgs, options)
  78. case "-Syu", "-Suy":
  79. err = yay.Upgrade(options)
  80. case "-Si":
  81. err = yay.SingleSearch(pkgs, options)
  82. case "yogurt":
  83. for _, pkg := range pkgs {
  84. err = yay.NumberMenu(pkg, options)
  85. break
  86. }
  87. case "--help", "-h":
  88. usage()
  89. default:
  90. err = yay.PassToPacman(op, pkgs, options)
  91. }
  92. if err != nil {
  93. fmt.Println(err)
  94. os.Exit(1)
  95. }
  96. }