Merge pull request #783 from Morganamilo/unexport

Unexport consts. Make default a literal
This commit is contained in:
Anna 2018-10-22 21:17:30 +01:00 committed by GitHub
commit 431118b6ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 110 additions and 112 deletions

View file

@ -67,13 +67,13 @@ func syncClean(parser *arguments) error {
} }
} }
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
if err = show(passToPacman(parser)); err != nil { if err = show(passToPacman(parser)); err != nil {
return err return err
} }
} }
if !(mode == ModeAUR || mode == ModeAny) { if !(mode == modeAUR || mode == modeAny) {
return nil return nil
} }

31
cmd.go
View file

@ -192,8 +192,7 @@ func handleVersion() {
func handlePrint() (err error) { func handlePrint() (err error) {
switch { switch {
case cmdArgs.existsArg("d", "defaultconfig"): case cmdArgs.existsArg("d", "defaultconfig"):
var tmpConfig Configuration tmpConfig := defaultSettings()
tmpConfig.defaultSettings()
tmpConfig.expandEnv() tmpConfig.expandEnv()
fmt.Printf("%v", tmpConfig) fmt.Printf("%v", tmpConfig)
case cmdArgs.existsArg("g", "currentconfig"): case cmdArgs.existsArg("g", "currentconfig"):
@ -238,8 +237,8 @@ func handleGetpkgbuild() error {
} }
func handleYogurt() error { func handleYogurt() error {
config.SearchMode = NumberMenu config.SearchMode = numberMenu
return numberMenu(cmdArgs.targets) return displayNumberMenu(cmdArgs.targets)
} }
func handleSync() error { func handleSync() error {
@ -247,9 +246,9 @@ func handleSync() error {
if cmdArgs.existsArg("s", "search") { if cmdArgs.existsArg("s", "search") {
if cmdArgs.existsArg("q", "quiet") { if cmdArgs.existsArg("q", "quiet") {
config.SearchMode = Minimal config.SearchMode = minimal
} else { } else {
config.SearchMode = Detailed config.SearchMode = detailed
} }
return syncSearch(targets) return syncSearch(targets)
} }
@ -286,7 +285,7 @@ func handleRemove() error {
} }
// NumberMenu presents a CLI for selecting packages to install. // NumberMenu presents a CLI for selecting packages to install.
func numberMenu(pkgS []string) (err error) { func displayNumberMenu(pkgS []string) (err error) {
var ( var (
aurErr, repoErr error aurErr, repoErr error
aq aurQuery aq aurQuery
@ -296,11 +295,11 @@ func numberMenu(pkgS []string) (err error) {
pkgS = removeInvalidTargets(pkgS) pkgS = removeInvalidTargets(pkgS)
if mode == ModeAUR || mode == ModeAny { if mode == modeAUR || mode == modeAny {
aq, aurErr = narrowSearch(pkgS, true) aq, aurErr = narrowSearch(pkgS, true)
lenaq = len(aq) lenaq = len(aq)
} }
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
pq, repoErr = queryRepo(pkgS) pq, repoErr = queryRepo(pkgS)
lenpq = len(pq) lenpq = len(pq)
if repoErr != nil { if repoErr != nil {
@ -312,18 +311,18 @@ func numberMenu(pkgS []string) (err error) {
return fmt.Errorf("No packages match search") return fmt.Errorf("No packages match search")
} }
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
if mode == ModeAUR || mode == ModeAny { if mode == modeAUR || mode == modeAny {
aq.printSearch(lenpq + 1) aq.printSearch(lenpq + 1)
} }
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
pq.printSearch() pq.printSearch()
} }
} else { } else {
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
pq.printSearch() pq.printSearch()
} }
if mode == ModeAUR || mode == ModeAny { if mode == modeAUR || mode == modeAny {
aq.printSearch(lenpq + 1) aq.printSearch(lenpq + 1)
} }
} }
@ -353,7 +352,7 @@ func numberMenu(pkgS []string) (err error) {
for i, pkg := range pq { for i, pkg := range pq {
target := len(pq) - i target := len(pq) - i
if config.SortMode == TopDown { if config.SortMode == topDown {
target = i + 1 target = i + 1
} }
@ -364,7 +363,7 @@ func numberMenu(pkgS []string) (err error) {
for i, pkg := range aq { for i, pkg := range aq {
target := len(aq) - i + len(pq) target := len(aq) - i + len(pq)
if config.SortMode == TopDown { if config.SortMode == topDown {
target = i + 1 + len(pq) target = i + 1 + len(pq)
} }

119
config.go
View file

@ -15,25 +15,21 @@ import (
// Verbosity settings for search // Verbosity settings for search
const ( const (
NumberMenu = iota numberMenu = iota
Detailed detailed
Minimal minimal
)
// Describes Sorting method for numberdisplay // Describes Sorting method for numberdisplay
const ( bottomUp = iota
BottomUp = iota topDown
TopDown
modeAUR targetMode = iota
modeRepo
modeAny
) )
type targetMode int type targetMode int
const (
ModeAUR targetMode = iota
ModeRepo
ModeAny
)
// Configuration stores yay's config. // Configuration stores yay's config.
type Configuration struct { type Configuration struct {
AURURL string `json:"aururl"` AURURL string `json:"aururl"`
@ -108,7 +104,7 @@ var vcsFile string
var shouldSaveConfig bool var shouldSaveConfig bool
// YayConf holds the current config values for yay. // YayConf holds the current config values for yay.
var config Configuration var config *Configuration
// AlpmConf holds the current config values for pacman. // AlpmConf holds the current config values for pacman.
var pacmanConf *pacmanconf.Config var pacmanConf *pacmanconf.Config
@ -117,7 +113,7 @@ var pacmanConf *pacmanconf.Config
var alpmHandle *alpm.Handle var alpmHandle *alpm.Handle
// Mode is used to restrict yay to AUR or repo only modes // Mode is used to restrict yay to AUR or repo only modes
var mode = ModeAny var mode = modeAny
var hideMenus = false var hideMenus = false
@ -137,51 +133,54 @@ func (config *Configuration) saveConfig() error {
return err return err
} }
func (config *Configuration) defaultSettings() { func defaultSettings() *Configuration {
buildDir := "$HOME/.cache/yay" config := &Configuration{
if os.Getenv("XDG_CACHE_HOME") != "" { AURURL: "https://aur.archlinux.org",
buildDir = "$XDG_CACHE_HOME/yay" BuildDir: "$HOME/.cache/yay",
CleanAfter: false,
Editor: "",
EditorFlags: "",
Devel: false,
MakepkgBin: "makepkg",
MakepkgConf: "",
NoConfirm: false,
PacmanBin: "pacman",
PGPFetch: true,
PacmanConf: "/etc/pacman.conf",
GpgFlags: "",
MFlags: "",
GitFlags: "",
SortMode: bottomUp,
CompletionInterval: 7,
SortBy: "votes",
SudoLoop: false,
TarBin: "bsdtar",
GitBin: "git",
GpgBin: "gpg",
TimeUpdate: false,
RequestSplitN: 150,
ReDownload: "no",
ReBuild: "no",
AnswerClean: "",
AnswerDiff: "",
AnswerEdit: "",
AnswerUpgrade: "",
RemoveMake: "ask",
GitClone: true,
Provides: true,
UpgradeMenu: true,
CleanMenu: true,
DiffMenu: true,
EditMenu: false,
UseAsk: false,
CombinedUpgrade: false,
} }
config.AURURL = "https://aur.archlinux.org" if os.Getenv("XDG_CACHE_HOME") != "" {
config.BuildDir = buildDir config.BuildDir = "$XDG_CACHE_HOME/yay"
config.CleanAfter = false }
config.Editor = ""
config.EditorFlags = "" return config
config.Devel = false
config.MakepkgBin = "makepkg"
config.MakepkgConf = ""
config.NoConfirm = false
config.PacmanBin = "pacman"
config.PGPFetch = true
config.PacmanConf = "/etc/pacman.conf"
config.GpgFlags = ""
config.MFlags = ""
config.GitFlags = ""
config.SortMode = BottomUp
config.CompletionInterval = 7
config.SortBy = "votes"
config.SudoLoop = false
config.TarBin = "bsdtar"
config.GitBin = "git"
config.GpgBin = "gpg"
config.TimeUpdate = false
config.RequestSplitN = 150
config.ReDownload = "no"
config.ReBuild = "no"
config.AnswerClean = ""
config.AnswerDiff = ""
config.AnswerEdit = ""
config.AnswerUpgrade = ""
config.RemoveMake = "ask"
config.GitClone = true
config.Provides = true
config.UpgradeMenu = true
config.CleanMenu = true
config.DiffMenu = true
config.EditMenu = false
config.UseAsk = false
config.CombinedUpgrade = false
} }
func (config *Configuration) expandEnv() { func (config *Configuration) expandEnv() {
@ -329,7 +328,7 @@ func toUsage(usages []string) alpm.Usage {
return alpm.UsageAll return alpm.UsageAll
} }
var ret alpm.Usage = 0 var ret alpm.Usage
for _, usage := range usages { for _, usage := range usages {
switch usage { switch usage {
case "Sync": case "Sync":

View file

@ -89,7 +89,7 @@ func (ds *depSolver) resolveTargets(pkgs []string) error {
var singleDb *alpm.Db var singleDb *alpm.Db
// aur/ prefix means we only check the aur // aur/ prefix means we only check the aur
if target.Db == "aur" || mode == ModeAUR { if target.Db == "aur" || mode == modeAUR {
ds.Targets = append(ds.Targets, target) ds.Targets = append(ds.Targets, target)
aurTargets = append(aurTargets, target.DepString()) aurTargets = append(aurTargets, target.DepString())
continue continue
@ -139,7 +139,7 @@ func (ds *depSolver) resolveTargets(pkgs []string) error {
ds.Targets = append(ds.Targets, target) ds.Targets = append(ds.Targets, target)
} }
if len(aurTargets) > 0 && (mode == ModeAny || mode == ModeAUR) { if len(aurTargets) > 0 && (mode == modeAny || mode == modeAUR) {
return ds.resolveAURPackages(aurTargets, true) return ds.resolveAURPackages(aurTargets, true)
} }

View file

@ -26,7 +26,7 @@ func install(parser *arguments) error {
warnings := &aurWarnings{} warnings := &aurWarnings{}
removeMake := false removeMake := false
if mode == ModeAny || mode == ModeRepo { if mode == modeAny || mode == modeRepo {
if config.CombinedUpgrade { if config.CombinedUpgrade {
if parser.existsArg("y", "refresh") { if parser.existsArg("y", "refresh") {
err = earlyRefresh(parser) err = earlyRefresh(parser)
@ -66,7 +66,7 @@ func install(parser *arguments) error {
arguments.op = "S" arguments.op = "S"
arguments.clearTargets() arguments.clearTargets()
if mode == ModeAUR { if mode == modeAUR {
arguments.delArg("u", "sysupgrade") arguments.delArg("u", "sysupgrade")
} }
@ -150,7 +150,7 @@ func install(parser *arguments) error {
arguments.addTarget(pkg) arguments.addTarget(pkg)
} }
if len(ds.Aur) == 0 && len(arguments.targets) == 0 && (!parser.existsArg("u", "sysupgrade") || mode == ModeAUR) { if len(ds.Aur) == 0 && len(arguments.targets) == 0 && (!parser.existsArg("u", "sysupgrade") || mode == modeAUR) {
fmt.Println(" there is nothing to do") fmt.Println(" there is nothing to do")
return nil return nil
} }
@ -378,7 +378,7 @@ func earlyPacmanCall(parser *arguments) error {
return err return err
} }
if mode == ModeRepo { if mode == modeRepo {
arguments.targets = targets arguments.targets = targets
} else { } else {
//separate aur and repo targets //separate aur and repo targets

View file

@ -208,7 +208,7 @@ func main() {
} }
exitOnError(setPaths()) exitOnError(setPaths())
config.defaultSettings() config = defaultSettings()
exitOnError(initHomeDirs()) exitOnError(initHomeDirs())
exitOnError(initConfig()) exitOnError(initConfig())
exitOnError(cmdArgs.parseCommandLine()) exitOnError(cmdArgs.parseCommandLine())

View file

@ -161,7 +161,7 @@ func (parser *arguments) needRoot() bool {
if parser.existsArg("i", "info") { if parser.existsArg("i", "info") {
return false return false
} }
if parser.existsArg("c", "clean") && mode == ModeAUR { if parser.existsArg("c", "clean") && mode == modeAUR {
return false return false
} }
return true return true
@ -514,9 +514,9 @@ func handleConfig(option, value string) bool {
case "notimeupdate": case "notimeupdate":
config.TimeUpdate = false config.TimeUpdate = false
case "topdown": case "topdown":
config.SortMode = TopDown config.SortMode = topDown
case "bottomup": case "bottomup":
config.SortMode = BottomUp config.SortMode = bottomUp
case "completioninterval": case "completioninterval":
n, err := strconv.Atoi(value) n, err := strconv.Atoi(value)
if err == nil { if err == nil {
@ -630,9 +630,9 @@ func handleConfig(option, value string) bool {
case "nocombinedupgrade": case "nocombinedupgrade":
config.CombinedUpgrade = false config.CombinedUpgrade = false
case "a", "aur": case "a", "aur":
mode = ModeAUR mode = modeAUR
case "repo": case "repo":
mode = ModeRepo mode = modeRepo
case "removemake": case "removemake":
config.RemoveMake = "yes" config.RemoveMake = "yes"
case "noremovemake": case "noremovemake":

View file

@ -64,13 +64,13 @@ func (q aurQuery) printSearch(start int) {
for i, res := range q { for i, res := range q {
var toprint string var toprint string
if config.SearchMode == NumberMenu { if config.SearchMode == numberMenu {
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
toprint += magenta(strconv.Itoa(len(q)+start-i-1) + " ") toprint += magenta(strconv.Itoa(len(q)+start-i-1) + " ")
} else { } else {
toprint += magenta(strconv.Itoa(start+i) + " ") toprint += magenta(strconv.Itoa(start+i) + " ")
} }
} else if config.SearchMode == Minimal { } else if config.SearchMode == minimal {
fmt.Println(res.Name) fmt.Println(res.Name)
continue continue
} }
@ -104,13 +104,13 @@ func (q aurQuery) printSearch(start int) {
func (s repoQuery) printSearch() { func (s repoQuery) printSearch() {
for i, res := range s { for i, res := range s {
var toprint string var toprint string
if config.SearchMode == NumberMenu { if config.SearchMode == numberMenu {
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
toprint += magenta(strconv.Itoa(len(s)-i) + " ") toprint += magenta(strconv.Itoa(len(s)-i) + " ")
} else { } else {
toprint += magenta(strconv.Itoa(i+1) + " ") toprint += magenta(strconv.Itoa(i+1) + " ")
} }
} else if config.SearchMode == Minimal { } else if config.SearchMode == minimal {
fmt.Println(res.Name()) fmt.Println(res.Name())
continue continue
} }
@ -452,7 +452,7 @@ func printNewsFeed() error {
return err return err
} }
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
for i := len(rss.Channel.Items) - 1; i >= 0; i-- { for i := len(rss.Channel.Items) - 1; i >= 0; i-- {
rss.Channel.Items[i].print(buildTime) rss.Channel.Items[i].print(buildTime)
} }

View file

@ -49,7 +49,7 @@ func (q aurQuery) Less(i, j int) bool {
result = q[i].PackageBaseID < q[j].PackageBaseID result = q[i].PackageBaseID < q[j].PackageBaseID
} }
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
return !result return !result
} }
@ -165,28 +165,28 @@ func syncSearch(pkgS []string) (err error) {
var aq aurQuery var aq aurQuery
var pq repoQuery var pq repoQuery
if mode == ModeAUR || mode == ModeAny { if mode == modeAUR || mode == modeAny {
aq, aurErr = narrowSearch(pkgS, true) aq, aurErr = narrowSearch(pkgS, true)
} }
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
pq, repoErr = queryRepo(pkgS) pq, repoErr = queryRepo(pkgS)
if repoErr != nil { if repoErr != nil {
return err return err
} }
} }
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
if mode == ModeAUR || mode == ModeAny { if mode == modeAUR || mode == modeAny {
aq.printSearch(1) aq.printSearch(1)
} }
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
pq.printSearch() pq.printSearch()
} }
} else { } else {
if mode == ModeRepo || mode == ModeAny { if mode == modeRepo || mode == modeAny {
pq.printSearch() pq.printSearch()
} }
if mode == ModeAUR || mode == ModeAny { if mode == modeAUR || mode == modeAny {
aq.printSearch(1) aq.printSearch(1)
} }
} }
@ -271,7 +271,7 @@ func queryRepo(pkgInputN []string) (s repoQuery, err error) {
return nil return nil
}) })
if config.SortMode == BottomUp { if config.SortMode == bottomUp {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i] s[i], s[j] = s[j], s[i]
} }
@ -291,10 +291,10 @@ func packageSlices(toCheck []string) (aur []string, repo []string, err error) {
db, name := splitDbFromName(_pkg) db, name := splitDbFromName(_pkg)
found := false found := false
if db == "aur" || mode == ModeAUR { if db == "aur" || mode == modeAUR {
aur = append(aur, _pkg) aur = append(aur, _pkg)
continue continue
} else if db != "" || mode == ModeRepo { } else if db != "" || mode == modeRepo {
repo = append(repo, _pkg) repo = append(repo, _pkg)
continue continue
} }

View file

@ -123,7 +123,7 @@ func upList(warnings *aurWarnings) (upSlice, upSlice, error) {
aurdata := make(map[string]*rpc.Pkg) aurdata := make(map[string]*rpc.Pkg)
if mode == ModeAny || mode == ModeRepo { if mode == modeAny || mode == modeRepo {
fmt.Println(bold(cyan("::") + bold(" Searching databases for updates..."))) fmt.Println(bold(cyan("::") + bold(" Searching databases for updates...")))
wg.Add(1) wg.Add(1)
go func() { go func() {
@ -133,7 +133,7 @@ func upList(warnings *aurWarnings) (upSlice, upSlice, error) {
}() }()
} }
if mode == ModeAny || mode == ModeAUR { if mode == modeAny || mode == modeAUR {
fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates..."))) fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates...")))
var _aurdata []*rpc.Pkg var _aurdata []*rpc.Pkg

View file

@ -114,12 +114,12 @@ func removeInvalidTargets(targets []string) []string {
for _, target := range targets { for _, target := range targets {
db, _ := splitDbFromName(target) db, _ := splitDbFromName(target)
if db == "aur" && mode == ModeRepo { if db == "aur" && mode == modeRepo {
fmt.Printf("%s %s %s\n", bold(yellow(arrow)), cyan(target), bold("Can't use target with option --repo -- skipping")) fmt.Printf("%s %s %s\n", bold(yellow(arrow)), cyan(target), bold("Can't use target with option --repo -- skipping"))
continue continue
} }
if db != "aur" && db != "" && mode == ModeAUR { if db != "aur" && db != "" && mode == modeAUR {
fmt.Printf("%s %s %s\n", bold(yellow(arrow)), cyan(target), bold("Can't use target with option --aur -- skipping")) fmt.Printf("%s %s %s\n", bold(yellow(arrow)), cyan(target), bold("Can't use target with option --aur -- skipping"))
continue continue
} }