summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brewcheck.go12
-rw-r--r--main.go8
-rw-r--r--print.go25
-rw-r--r--statistics.go2
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)
}
diff --git a/main.go b/main.go
index 352517c..53f25d9 100644
--- a/main.go
+++ b/main.go
@@ -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
},
}
diff --git a/print.go b/print.go
index 53b0f5c..1e7ce08 100644
--- a/print.go
+++ b/print.go
@@ -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 === //