Skip to content

Commit

Permalink
Unexport consts. Make default a literal
Browse files Browse the repository at this point in the history
Signed-off-by: Jguer <me@jguer.space>
  • Loading branch information
Jguer authored and Morganamilo committed Oct 22, 2018
1 parent b40b1ef commit 2ed7df4
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 111 deletions.
4 changes: 2 additions & 2 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return err
}
}

if !(mode == ModeAUR || mode == ModeAny) {
if !(mode == modeAUR || mode == modeAny) {
return nil
}

Expand Down
31 changes: 15 additions & 16 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ func handleVersion() {
func handlePrint() (err error) {
switch {
case cmdArgs.existsArg("d", "defaultconfig"):
var tmpConfig Configuration
tmpConfig.defaultSettings()
tmpConfig := defaultSettings()
tmpConfig.expandEnv()
fmt.Printf("%v", tmpConfig)
case cmdArgs.existsArg("g", "currentconfig"):
Expand Down Expand Up @@ -238,18 +237,18 @@ func handleGetpkgbuild() error {
}

func handleYogurt() error {
config.SearchMode = NumberMenu
return numberMenu(cmdArgs.targets)
config.SearchMode = numberMenu
return displayNumberMenu(cmdArgs.targets)
}

func handleSync() error {
targets := cmdArgs.targets

if cmdArgs.existsArg("s", "search") {
if cmdArgs.existsArg("q", "quiet") {
config.SearchMode = Minimal
config.SearchMode = minimal
} else {
config.SearchMode = Detailed
config.SearchMode = detailed
}
return syncSearch(targets)
}
Expand Down Expand Up @@ -286,7 +285,7 @@ func handleRemove() error {
}

// NumberMenu presents a CLI for selecting packages to install.
func numberMenu(pkgS []string) (err error) {
func displayNumberMenu(pkgS []string) (err error) {
var (
aurErr, repoErr error
aq aurQuery
Expand All @@ -296,11 +295,11 @@ func numberMenu(pkgS []string) (err error) {

pkgS = removeInvalidTargets(pkgS)

if mode == ModeAUR || mode == ModeAny {
if mode == modeAUR || mode == modeAny {
aq, aurErr = narrowSearch(pkgS, true)
lenaq = len(aq)
}
if mode == ModeRepo || mode == ModeAny {
if mode == modeRepo || mode == modeAny {
pq, repoErr = queryRepo(pkgS)
lenpq = len(pq)
if repoErr != nil {
Expand All @@ -312,18 +311,18 @@ func numberMenu(pkgS []string) (err error) {
return fmt.Errorf("No packages match search")
}

if config.SortMode == BottomUp {
if mode == ModeAUR || mode == ModeAny {
if config.SortMode == bottomUp {
if mode == modeAUR || mode == modeAny {
aq.printSearch(lenpq + 1)
}
if mode == ModeRepo || mode == ModeAny {
if mode == modeRepo || mode == modeAny {
pq.printSearch()
}
} else {
if mode == ModeRepo || mode == ModeAny {
if mode == modeRepo || mode == modeAny {
pq.printSearch()
}
if mode == ModeAUR || mode == ModeAny {
if mode == modeAUR || mode == modeAny {
aq.printSearch(lenpq + 1)
}
}
Expand Down Expand Up @@ -353,7 +352,7 @@ func numberMenu(pkgS []string) (err error) {

for i, pkg := range pq {
target := len(pq) - i
if config.SortMode == TopDown {
if config.SortMode == topDown {
target = i + 1
}

Expand All @@ -364,7 +363,7 @@ func numberMenu(pkgS []string) (err error) {

for i, pkg := range aq {
target := len(aq) - i + len(pq)
if config.SortMode == TopDown {
if config.SortMode == topDown {
target = i + 1 + len(pq)
}

Expand Down
117 changes: 58 additions & 59 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@ import (

// Verbosity settings for search
const (
NumberMenu = iota
Detailed
Minimal
)
numberMenu = iota
detailed
minimal

// Describes Sorting method for numberdisplay
const (
BottomUp = iota
TopDown
// Describes Sorting method for numberdisplay
bottomUp = iota
topDown

modeAUR targetMode = iota
modeRepo
modeAny
)

type targetMode int

const (
ModeAUR targetMode = iota
ModeRepo
ModeAny
)

// Configuration stores yay's config.
type Configuration struct {
AURURL string `json:"aururl"`
Expand Down Expand Up @@ -108,7 +104,7 @@ var vcsFile string
var shouldSaveConfig bool

// YayConf holds the current config values for yay.
var config Configuration
var config *Configuration

// AlpmConf holds the current config values for pacman.
var pacmanConf *pacmanconf.Config
Expand All @@ -117,7 +113,7 @@ var pacmanConf *pacmanconf.Config
var alpmHandle *alpm.Handle

// Mode is used to restrict yay to AUR or repo only modes
var mode = ModeAny
var mode = modeAny

var hideMenus = false

Expand All @@ -137,51 +133,54 @@ func (config *Configuration) saveConfig() error {
return err
}

func (config *Configuration) defaultSettings() {
buildDir := "$HOME/.cache/yay"
func defaultSettings() *Configuration {
config := &Configuration{
AURURL: "https://aur.archlinux.org",
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,
}

if os.Getenv("XDG_CACHE_HOME") != "" {
buildDir = "$XDG_CACHE_HOME/yay"
config.BuildDir = "$XDG_CACHE_HOME/yay"
}

config.AURURL = "https://aur.archlinux.org"
config.BuildDir = buildDir
config.CleanAfter = false
config.Editor = ""
config.EditorFlags = ""
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
return config
}

func (config *Configuration) expandEnv() {
Expand Down Expand Up @@ -329,7 +328,7 @@ func toUsage(usages []string) alpm.Usage {
return alpm.UsageAll
}

var ret alpm.Usage = 0
var ret alpm.Usage
for _, usage := range usages {
switch usage {
case "Sync":
Expand Down
4 changes: 2 additions & 2 deletions depSolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (ds *depSolver) resolveTargets(pkgs []string) error {
var singleDb *alpm.Db

// 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)
aurTargets = append(aurTargets, target.DepString())
continue
Expand Down Expand Up @@ -139,7 +139,7 @@ func (ds *depSolver) resolveTargets(pkgs []string) error {
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)
}

Expand Down
8 changes: 4 additions & 4 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func install(parser *arguments) error {
warnings := &aurWarnings{}
removeMake := false

if mode == ModeAny || mode == ModeRepo {
if mode == modeAny || mode == modeRepo {
if config.CombinedUpgrade {
if parser.existsArg("y", "refresh") {
err = earlyRefresh(parser)
Expand Down Expand Up @@ -66,7 +66,7 @@ func install(parser *arguments) error {
arguments.op = "S"
arguments.clearTargets()

if mode == ModeAUR {
if mode == modeAUR {
arguments.delArg("u", "sysupgrade")
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func install(parser *arguments) error {
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")
return nil
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func earlyPacmanCall(parser *arguments) error {
return err
}

if mode == ModeRepo {
if mode == modeRepo {
arguments.targets = targets
} else {
//separate aur and repo targets
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func main() {
}

exitOnError(setPaths())
config.defaultSettings()
config = defaultSettings()
exitOnError(initHomeDirs())
exitOnError(initConfig())
exitOnError(cmdArgs.parseCommandLine())
Expand Down
10 changes: 5 additions & 5 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (parser *arguments) needRoot() bool {
if parser.existsArg("i", "info") {
return false
}
if parser.existsArg("c", "clean") && mode == ModeAUR {
if parser.existsArg("c", "clean") && mode == modeAUR {
return false
}
return true
Expand Down Expand Up @@ -514,9 +514,9 @@ func handleConfig(option, value string) bool {
case "notimeupdate":
config.TimeUpdate = false
case "topdown":
config.SortMode = TopDown
config.SortMode = topDown
case "bottomup":
config.SortMode = BottomUp
config.SortMode = bottomUp
case "completioninterval":
n, err := strconv.Atoi(value)
if err == nil {
Expand Down Expand Up @@ -630,9 +630,9 @@ func handleConfig(option, value string) bool {
case "nocombinedupgrade":
config.CombinedUpgrade = false
case "a", "aur":
mode = ModeAUR
mode = modeAUR
case "repo":
mode = ModeRepo
mode = modeRepo
case "removemake":
config.RemoveMake = "yes"
case "noremovemake":
Expand Down
Loading

0 comments on commit 2ed7df4

Please sign in to comment.