args.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package settings
  2. import (
  3. "strconv"
  4. "strings"
  5. "github.com/Jguer/yay/v12/pkg/settings/parser"
  6. "github.com/Jguer/yay/v12/pkg/text"
  7. )
  8. func (c *Configuration) ParseCommandLine(a *parser.Arguments) error {
  9. if err := a.Parse(); err != nil {
  10. return err
  11. }
  12. c.extractYayOptions(a)
  13. // Reload CmdBuilder
  14. c.Runtime.CmdBuilder = c.CmdBuilder(nil)
  15. return nil
  16. }
  17. func (c *Configuration) extractYayOptions(a *parser.Arguments) {
  18. for option, value := range a.Options {
  19. if c.handleOption(option, value.First()) {
  20. a.DelArg(option)
  21. }
  22. }
  23. c.AURURL = strings.TrimRight(c.AURURL, "/")
  24. // if AurRPCURL is set, use that for /rpc calls
  25. if c.AURRPCURL == "" {
  26. c.AURRPCURL = c.AURURL + "/rpc?"
  27. return
  28. }
  29. if !strings.HasSuffix(c.AURRPCURL, "?") {
  30. if strings.HasSuffix(c.AURRPCURL, "/rpc") {
  31. c.AURRPCURL += "?"
  32. } else {
  33. c.AURRPCURL = strings.TrimRight(c.AURRPCURL, "/") + "/rpc?"
  34. }
  35. }
  36. }
  37. func (c *Configuration) handleOption(option, value string) bool {
  38. switch option {
  39. case "aururl":
  40. c.AURURL = value
  41. case "aurrpcurl":
  42. c.AURRPCURL = value
  43. case "save":
  44. c.SaveConfig = true
  45. case "afterclean", "cleanafter":
  46. c.CleanAfter = true
  47. case "noafterclean", "nocleanafter":
  48. c.CleanAfter = false
  49. case "debug":
  50. c.Debug = true
  51. text.GlobalLogger.Debug = true
  52. return false
  53. case "devel":
  54. c.Devel = true
  55. case "nodevel":
  56. c.Devel = false
  57. case "timeupdate":
  58. c.TimeUpdate = true
  59. case "notimeupdate":
  60. c.TimeUpdate = false
  61. case "topdown":
  62. c.BottomUp = false
  63. case "bottomup":
  64. c.BottomUp = true
  65. case "singlelineresults":
  66. c.SingleLineResults = true
  67. case "doublelineresults":
  68. c.SingleLineResults = false
  69. case "completioninterval":
  70. n, err := strconv.Atoi(value)
  71. if err == nil {
  72. c.CompletionInterval = n
  73. }
  74. case "sortby":
  75. c.SortBy = value
  76. case "searchby":
  77. c.SearchBy = value
  78. case "noconfirm":
  79. NoConfirm = true
  80. case "config":
  81. c.PacmanConf = value
  82. case "redownload":
  83. c.ReDownload = "yes"
  84. case "redownloadall":
  85. c.ReDownload = "all"
  86. case "noredownload":
  87. c.ReDownload = "no"
  88. case "rebuild":
  89. c.ReBuild = parser.RebuildModeYes
  90. case "rebuildall":
  91. c.ReBuild = parser.RebuildModeAll
  92. case "rebuildtree":
  93. c.ReBuild = parser.RebuildModeTree
  94. case "norebuild":
  95. c.ReBuild = parser.RebuildModeNo
  96. case "batchinstall":
  97. c.BatchInstall = true
  98. case "nobatchinstall":
  99. c.BatchInstall = false
  100. case "answerclean":
  101. c.AnswerClean = value
  102. case "noanswerclean":
  103. c.AnswerClean = ""
  104. case "answerdiff":
  105. c.AnswerDiff = value
  106. case "noanswerdiff":
  107. c.AnswerDiff = ""
  108. case "answeredit":
  109. c.AnswerEdit = value
  110. case "noansweredit":
  111. c.AnswerEdit = ""
  112. case "answerupgrade":
  113. c.AnswerUpgrade = value
  114. case "noanswerupgrade":
  115. c.AnswerUpgrade = ""
  116. case "gpgflags":
  117. c.GpgFlags = value
  118. case "mflags":
  119. c.MFlags = value
  120. case "gitflags":
  121. c.GitFlags = value
  122. case "builddir":
  123. c.BuildDir = value
  124. case "editor":
  125. c.Editor = value
  126. case "editorflags":
  127. c.EditorFlags = value
  128. case "makepkg":
  129. c.MakepkgBin = value
  130. case "makepkgconf":
  131. c.MakepkgConf = value
  132. case "nomakepkgconf":
  133. c.MakepkgConf = ""
  134. case "pacman":
  135. c.PacmanBin = value
  136. case "git":
  137. c.GitBin = value
  138. case "gpg":
  139. c.GpgBin = value
  140. case "sudo":
  141. c.SudoBin = value
  142. case "sudoflags":
  143. c.SudoFlags = value
  144. case "requestsplitn":
  145. n, err := strconv.Atoi(value)
  146. if err == nil && n > 0 {
  147. c.RequestSplitN = n
  148. }
  149. case "sudoloop":
  150. c.SudoLoop = true
  151. case "nosudoloop":
  152. c.SudoLoop = false
  153. case "provides":
  154. c.Provides = true
  155. case "noprovides":
  156. c.Provides = false
  157. case "pgpfetch":
  158. c.PGPFetch = true
  159. case "nopgpfetch":
  160. c.PGPFetch = false
  161. case "cleanmenu":
  162. c.CleanMenu = true
  163. case "nocleanmenu":
  164. c.CleanMenu = false
  165. case "diffmenu":
  166. c.DiffMenu = true
  167. case "nodiffmenu":
  168. c.DiffMenu = false
  169. case "editmenu":
  170. c.EditMenu = true
  171. case "noeditmenu":
  172. c.EditMenu = false
  173. case "useask":
  174. c.UseAsk = true
  175. case "nouseask":
  176. c.UseAsk = false
  177. case "combinedupgrade":
  178. c.CombinedUpgrade = true
  179. case "nocombinedupgrade":
  180. c.CombinedUpgrade = false
  181. case "a", "aur":
  182. c.Mode = parser.ModeAUR
  183. case "repo":
  184. c.Mode = parser.ModeRepo
  185. case "removemake":
  186. c.RemoveMake = "yes"
  187. case "noremovemake":
  188. c.RemoveMake = "no"
  189. case "askremovemake":
  190. c.RemoveMake = "ask"
  191. case "separatesources":
  192. c.SeparateSources = true
  193. case "noseparatesources":
  194. c.SeparateSources = false
  195. default:
  196. return false
  197. }
  198. return true
  199. }