From bc6028348b8ffdb6be78c79eee1dafafd3e9b4d2 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 24 Jul 2018 14:42:43 +0100 Subject: [PATCH] Make the completion refresh time configurable The default setting is 7 days. The user can specify a different time in days. -1 can be set to never refresh while 0 can be used to always refresh. --- cmd.go | 5 ++++ completions.go | 2 +- config.go | 78 ++++++++++++++++++++++++++------------------------ parser.go | 2 ++ 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/cmd.go b/cmd.go index cfa67211..5dffe1aa 100644 --- a/cmd.go +++ b/cmd.go @@ -221,6 +221,11 @@ func handleConfig(option, value string) bool { config.SortMode = TopDown case "bottomup": config.SortMode = BottomUp + case "completioninterval": + n, err := strconv.Atoi(value) + if err == nil { + config.CompletionInterval = n + } case "sortby": config.SortBy = value case "noconfirm": diff --git a/completions.go b/completions.go index ba52d702..2a83f2ff 100644 --- a/completions.go +++ b/completions.go @@ -52,7 +52,7 @@ func updateCompletion(force bool) error { path := filepath.Join(cacheHome, "completion.cache") info, err := os.Stat(path) - if os.IsNotExist(err) || time.Since(info.ModTime()).Hours() >= 7*24 || force { + if os.IsNotExist(err) || (config.CompletionInterval != -1 && time.Since(info.ModTime()).Hours() >= float64(config.CompletionInterval*24)) || force { os.MkdirAll(filepath.Dir(path), 0755) out, errf := os.Create(path) if errf != nil { diff --git a/config.go b/config.go index 06be4bdb..cff3e77d 100644 --- a/config.go +++ b/config.go @@ -35,44 +35,45 @@ const ( // Configuration stores yay's config. type Configuration struct { - BuildDir string `json:"buildDir"` - Editor string `json:"editor"` - EditorFlags string `json:"editorflags"` - MakepkgBin string `json:"makepkgbin"` - MakepkgConf string `json:"makepkgconf"` - PacmanBin string `json:"pacmanbin"` - PacmanConf string `json:"pacmanconf"` - TarBin string `json:"tarbin"` - ReDownload string `json:"redownload"` - ReBuild string `json:"rebuild"` - AnswerClean string `json:"answerclean"` - AnswerDiff string `json:"answerdiff"` - AnswerEdit string `json:"answeredit"` - AnswerUpgrade string `json:"answerupgrade"` - GitBin string `json:"gitbin"` - GpgBin string `json:"gpgbin"` - GpgFlags string `json:"gpgflags"` - MFlags string `json:"mflags"` - SortBy string `json:"sortby"` - GitFlags string `json:"gitflags"` - RemoveMake string `json:"removemake"` - RequestSplitN int `json:"requestsplitn"` - SearchMode int `json:"-"` - SortMode int `json:"sortmode"` - SudoLoop bool `json:"sudoloop"` - TimeUpdate bool `json:"timeupdate"` - NoConfirm bool `json:"-"` - Devel bool `json:"devel"` - CleanAfter bool `json:"cleanAfter"` - GitClone bool `json:"gitclone"` - Provides bool `json:"provides"` - PGPFetch bool `json:"pgpfetch"` - UpgradeMenu bool `json:"upgrademenu"` - CleanMenu bool `json:"cleanmenu"` - DiffMenu bool `json:"diffmenu"` - EditMenu bool `json:"editmenu"` - CombinedUpgrade bool `json:"combinedupgrade"` - UseAsk bool `json:"useask"` + BuildDir string `json:"buildDir"` + Editor string `json:"editor"` + EditorFlags string `json:"editorflags"` + MakepkgBin string `json:"makepkgbin"` + MakepkgConf string `json:"makepkgconf"` + PacmanBin string `json:"pacmanbin"` + PacmanConf string `json:"pacmanconf"` + TarBin string `json:"tarbin"` + ReDownload string `json:"redownload"` + ReBuild string `json:"rebuild"` + AnswerClean string `json:"answerclean"` + AnswerDiff string `json:"answerdiff"` + AnswerEdit string `json:"answeredit"` + AnswerUpgrade string `json:"answerupgrade"` + GitBin string `json:"gitbin"` + GpgBin string `json:"gpgbin"` + GpgFlags string `json:"gpgflags"` + MFlags string `json:"mflags"` + SortBy string `json:"sortby"` + GitFlags string `json:"gitflags"` + RemoveMake string `json:"removemake"` + RequestSplitN int `json:"requestsplitn"` + SearchMode int `json:"-"` + SortMode int `json:"sortmode"` + CompletionInterval int `json:"completionrefreshtime"` + SudoLoop bool `json:"sudoloop"` + TimeUpdate bool `json:"timeupdate"` + NoConfirm bool `json:"-"` + Devel bool `json:"devel"` + CleanAfter bool `json:"cleanAfter"` + GitClone bool `json:"gitclone"` + Provides bool `json:"provides"` + PGPFetch bool `json:"pgpfetch"` + UpgradeMenu bool `json:"upgrademenu"` + CleanMenu bool `json:"cleanmenu"` + DiffMenu bool `json:"diffmenu"` + EditMenu bool `json:"editmenu"` + CombinedUpgrade bool `json:"combinedupgrade"` + UseAsk bool `json:"useask"` } var version = "7.885" @@ -163,6 +164,7 @@ func defaultSettings(config *Configuration) { config.MFlags = "" config.GitFlags = "" config.SortMode = BottomUp + config.CompletionInterval = 7 config.SortBy = "votes" config.SudoLoop = false config.TarBin = "bsdtar" diff --git a/parser.go b/parser.go index cd91c68f..9090b35a 100644 --- a/parser.go +++ b/parser.go @@ -472,6 +472,8 @@ func hasParam(arg string) bool { return true case "answerupgrade": return true + case "completioninterval": + return true case "sortby": return true default: