diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-21 08:52:13 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-21 08:52:13 +0800 |
| commit | c2f95c4002c3a3324752b7308c36cd8a0465e9fd (patch) | |
| tree | f3a924b651cfa105b2dd6ee4e3bac53bad87b581 | |
| parent | 4528958c13a5047d1e9e30d266996c93175e3731 (diff) | |
style: rename vars shorter to be idiomatic and fix typo
| -rw-r--r-- | brewcheck.go | 12 | ||||
| -rw-r--r-- | main.go | 8 | ||||
| -rw-r--r-- | print.go | 25 | ||||
| -rw-r--r-- | statistics.go | 2 |
4 files changed, 24 insertions, 23 deletions
diff --git a/brewcheck.go b/brewcheck.go index 51d8e17..677b2d7 100644 --- a/brewcheck.go +++ b/brewcheck.go @@ -11,14 +11,14 @@ import ( "github.com/fatih/color" ) -const cacheTTL = 3 * 24 * time.Hour // 3 days +const TTL = 3 * 24 * time.Hour // 3 days func EnsureBrewAvailable() { - cacheFile := filepath.Join(xdg.CacheHome, "wthis", "brew-checked") + cache := filepath.Join(xdg.CacheHome, "wthis", "brew-checked") // 1. check if cache file exists and is fresh - if info, err := os.Stat(cacheFile); err == nil { - if time.Since(info.ModTime()) < cacheTTL { + if info, err := os.Stat(cache); err == nil { + if time.Since(info.ModTime()) < TTL { return // recently verified that brew exists } } @@ -32,6 +32,6 @@ func EnsureBrewAvailable() { } // 3. write cache - _ = os.MkdirAll(filepath.Dir(cacheFile), 0o755) - _ = os.WriteFile(cacheFile, []byte{}, 0o644) + _ = os.MkdirAll(filepath.Dir(cache), 0o755) + _ = os.WriteFile(cache, []byte{}, 0o644) } @@ -24,11 +24,11 @@ func main() { pkgName := cmd.Args().First() // prompt showLoadingPrompt(fmt.Sprintf("What the heck is \"%s\"", pkgName)) - // search and print - formulae, cask := GetBrewInfo(pkgName) - data := UnifyInfo(formulae, cask, pkgName) + // search, tidy up, and print + formula, cask := GetBrewInfo(pkgName) + stat := NewStatistics(formula, cask, pkgName) hideLoadingPrompt() - PrintInfo(data) + PrintInfo(stat) return nil }, } @@ -31,17 +31,18 @@ func printHeader(data *statistics) { } func printUserInteractionSummary(data *statistics) { - printed1 := printInstallDesc( + a := printInstallDesc( data.Type == "formula", data.InstalledAsDependency, data.InstalledOnRequest, data.InstalledVersion, data.ReverseDependencies) - printed2 := printRecentActivity( + b := printRecentActivity( data.InstalledVersion, data.LastAccessTime, data.BinaryExists) - if printed1 || printed2 { + + if a || b { // add empty line only if any of above prints info fmt.Println() } } @@ -74,14 +75,14 @@ func printTypeNameAndDesc(typ string, name string, desc string) { // answers questions like "how it got here?" func printInstallDesc( - isFormulae bool, + isFormula bool, asDependency bool, onRequest bool, version string, reverseDependencies []string, ) (printed bool) { - // formulae only - if !isFormulae { + // formula only + if !isFormula { return false } @@ -109,13 +110,13 @@ func printRecentActivity( } // print usage info - humanReadableDuration := durafmt.ParseShort(time.Since(atime)).String() + duratext := durafmt.ParseShort(time.Since(atime)).String() if atime.Nanosecond() == 0 { color.Blue("► You never used this.") } else if time.Since(atime) < 24*7*time.Hour { - color.Blue("► You used this in %s.", humanReadableDuration) + color.Blue("► You used this in %s.", duratext) } else { - color.Blue("► You haven't used this for %s.", humanReadableDuration) + color.Blue("► You haven't used this for %s.", duratext) } return true } @@ -124,8 +125,8 @@ func printRecentActivity( // prints badges like [Outdated] [Up to date] ... // used by printMetadata -func printVersionInfo(installedVersion string, outdated bool) { - if installedVersion != "" { +func printVersionInfo(installed string, outdated bool) { + if installed != "" { var installBadge string var installBadgeColor color.Attribute if outdated { @@ -135,7 +136,7 @@ func printVersionInfo(installedVersion string, outdated bool) { installBadge = "[Up to date]" installBadgeColor = color.FgGreen } - fmt.Printf("📦 %s", installedVersion) + fmt.Printf("📦 %s", installed) color.New(installBadgeColor).Printf(" %s\n", installBadge) } else { color.Red("📦 [Not installed]") diff --git a/statistics.go b/statistics.go index 80017c9..6c7ed88 100644 --- a/statistics.go +++ b/statistics.go @@ -25,7 +25,7 @@ type statistics struct { ReverseDependencies []string; } -func UnifyInfo(formula *FormulaInfo, cask *CaskInfo, pkgName string) (*statistics) { +func NewStatistics(formula *FormulaInfo, cask *CaskInfo, pkgName string) (*statistics) { var statObject statistics // === formula/cask specific === // |
