From 3ce76a4e0be8edef6ee90ff4edb291aadb200e99 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Fri, 21 Nov 2025 08:57:56 +0800 Subject: refactor: move print entry point to statistics.Print() --- main.go | 2 +- print.go | 21 +++------------------ statistics.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 53f25d9..237fdb7 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ func main() { formula, cask := GetBrewInfo(pkgName) stat := NewStatistics(formula, cask, pkgName) hideLoadingPrompt() - PrintInfo(stat) + stat.Print() return nil }, } diff --git a/print.go b/print.go index 1e7ce08..ca10b98 100644 --- a/print.go +++ b/print.go @@ -8,29 +8,14 @@ import ( "github.com/hako/durafmt" ) -// === Print Entry Point === // - -func PrintInfo(data *statistics) { - if data == nil { - fmt.Println("Package not found.") - return - } - - printHeader(data) - printUserInteractionSummary(data) - printMetadata(data) - - fmt.Println() -} - // === Main Sections === // -func printHeader(data *statistics) { +func PrintHeader(data *statistics) { printTypeNameAndDesc(data.Type, data.Name, data.Desc) fmt.Println() } -func printUserInteractionSummary(data *statistics) { +func PrintUserInteractionSummary(data *statistics) { a := printInstallDesc( data.Type == "formula", data.InstalledAsDependency, @@ -47,7 +32,7 @@ func printUserInteractionSummary(data *statistics) { } } -func printMetadata(data *statistics) { +func PrintMetadata(data *statistics) { printVersionInfo( data.InstalledVersion, data.Outdated) diff --git a/statistics.go b/statistics.go index 6c7ed88..0cd7d44 100644 --- a/statistics.go +++ b/statistics.go @@ -5,6 +5,7 @@ import ( "path/filepath" "syscall" "time" + "fmt" ) type statistics struct { @@ -73,3 +74,15 @@ func NewStatistics(formula *FormulaInfo, cask *CaskInfo, pkgName string) (*stati return &statObject } + +func (s *statistics) Print() { + if s == nil { + fmt.Println("Package not found.") + return + } + + PrintHeader(s) + PrintUserInteractionSummary(s) + PrintMetadata(s) + fmt.Println() +} -- cgit v1.2.3