From 886e3980c03cd056157164bc2a4a712167849270 Mon Sep 17 00:00:00 2001 From: eltrac Date: Wed, 27 May 2026 14:48:37 +0800 Subject: fix: --no-cache not working for list command --- actions.go | 4 ++-- brewget.go | 11 ++++++++--- main.go | 9 ++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/actions.go b/actions.go index d672332..ce77e1c 100644 --- a/actions.go +++ b/actions.go @@ -94,8 +94,8 @@ func initStat(pkgName string) *statistics { return stat } -func runList() error { - depmap := GetBrewDeps() +func runList(useCache bool) error { + depmap := GetBrewDeps(useCache) list := GetBrewList() keys := []string{} diff --git a/brewget.go b/brewget.go index b5c8c8a..5b33b01 100644 --- a/brewget.go +++ b/brewget.go @@ -118,14 +118,19 @@ func GetBrewList() []string { return list } -func GetBrewDeps() map[string][]string { +func GetBrewDeps(useCache bool) map[string][]string { depmap := map[string][]string{} // Try reading from cache const cachepath = "depmap.json" - cache_data, cache_hit := ReadCache(cachepath, brewDepCacheTTL) + var cache_data []byte + var cache_hit bool - if cache_hit { + if (useCache) { + cache_data, cache_hit = ReadCache(cachepath, brewDepCacheTTL) + } + + if cache_hit && useCache { // if cache hit, decode err := json.Unmarshal(cache_data, &depmap) if err != nil { diff --git a/main.go b/main.go index d58fba3..6ea78c1 100644 --- a/main.go +++ b/main.go @@ -73,9 +73,16 @@ func main() { Value: false, Destination: &ListNoDep, }, + &cli.BoolFlag{ + Name: "no-cache", + Aliases: []string{"nc"}, + Usage: "Disable caching", + Value: false, + Destination: &NoCache, + }, }, Action: func(ctx context.Context, cmd *cli.Command) error { - return runList() + return runList(!NoCache) }, }, { -- cgit v1.2.3