diff options
| -rw-r--r-- | animation.go | 4 | ||||
| -rw-r--r-- | brewcheck.go | 4 | ||||
| -rw-r--r-- | brewget.go | 6 | ||||
| -rw-r--r-- | main.go | 60 | ||||
| -rw-r--r-- | print.go | 14 | ||||
| -rw-r--r-- | statistics.go | 28 |
6 files changed, 58 insertions, 58 deletions
diff --git a/animation.go b/animation.go index 226f309..5d2bc47 100644 --- a/animation.go +++ b/animation.go @@ -2,9 +2,9 @@ package main import ( "fmt" - "time" - "strings" "github.com/fatih/color" + "strings" + "time" ) var loadingDone chan bool diff --git a/brewcheck.go b/brewcheck.go index 677b2d7..ac34786 100644 --- a/brewcheck.go +++ b/brewcheck.go @@ -1,11 +1,11 @@ package main import ( + "fmt" "os" "os/exec" "path/filepath" "time" - "fmt" "github.com/adrg/xdg" "github.com/fatih/color" @@ -19,7 +19,7 @@ func EnsureBrewAvailable() { // 1. check if cache file exists and is fresh if info, err := os.Stat(cache); err == nil { if time.Since(info.ModTime()) < TTL { - return // recently verified that brew exists + return // recently verified that brew exists } } @@ -1,11 +1,11 @@ package main import ( + "bytes" "encoding/json" + "github.com/fatih/color" "os/exec" "strings" - "bytes" - "github.com/fatih/color" ) type FormulaInfo struct { @@ -62,7 +62,7 @@ func GetBrewInfo(pkg string) (*FormulaInfo, *CaskInfo) { return nil, nil // not found } -func GetBrewUses(pkg string) ([]string) { +func GetBrewUses(pkg string) []string { cmd := exec.Command("brew", "uses", "--installed", pkg) var out bytes.Buffer cmd.Stdout = &out @@ -1,42 +1,42 @@ package main import ( - "fmt" - "os" - "context" - "log" - "github.com/fatih/color" - "github.com/urfave/cli/v3" + "context" + "fmt" + "github.com/fatih/color" + "github.com/urfave/cli/v3" + "log" + "os" ) func main() { EnsureBrewAvailable() - // declare CLI app - cmd := &cli.Command{ - Name: "wthis", - Usage: "Fetch information of a Homebrew formulae or cask, like how it got installed, reverse dependencies, etc.", - Action: func(ctx context.Context, cmd *cli.Command) error { - // check args - if cmd.Args().Len() == 0 { - printErrorAndExit("Please provide a formulae/cask name.") - } - pkgName := cmd.Args().First() - // prompt - showLoadingPrompt(fmt.Sprintf("What the heck is \"%s\"", pkgName)) - // search, tidy up, and print - formula, cask := GetBrewInfo(pkgName) - stat := NewStatistics(formula, cask, pkgName) - hideLoadingPrompt() - stat.Print() - return nil - }, - } + // declare CLI app + cmd := &cli.Command{ + Name: "wthis", + Usage: "Fetch information of a Homebrew formulae or cask, like how it got installed, reverse dependencies, etc.", + Action: func(ctx context.Context, cmd *cli.Command) error { + // check args + if cmd.Args().Len() == 0 { + printErrorAndExit("Please provide a formulae/cask name.") + } + pkgName := cmd.Args().First() + // prompt + showLoadingPrompt(fmt.Sprintf("What the heck is \"%s\"", pkgName)) + // search, tidy up, and print + formula, cask := GetBrewInfo(pkgName) + stat := NewStatistics(formula, cask, pkgName) + hideLoadingPrompt() + stat.Print() + return nil + }, + } - // run command and handle error - if err := cmd.Run(context.Background(), os.Args); err != nil { - log.Fatal(err) - } + // run command and handle error + if err := cmd.Run(context.Background(), os.Args); err != nil { + log.Fatal(err) + } } func printErrorAndExit(msg string) { @@ -3,9 +3,9 @@ package main import ( "fmt" "github.com/fatih/color" + "github.com/hako/durafmt" "strings" "time" - "github.com/hako/durafmt" ) // === Main Sections === // @@ -24,10 +24,10 @@ func PrintUserInteractionSummary(data *statistics) { data.ReverseDependencies) b := printRecentActivity( data.InstalledVersion, - data.LastAccessTime, + data.LastAccessTime, data.BinaryExists) - if a || b { // add empty line only if any of above prints info + if a || b { // add empty line only if any of above prints info fmt.Println() } } @@ -44,10 +44,10 @@ func PrintMetadata(data *statistics) { func printTypeNameAndDesc(typ string, name string, desc string) { var icon string switch typ { - case "formula": - icon = "🍺" - case "cask": - icon = "☕️" + case "formula": + icon = "🍺" + case "cask": + icon = "☕️" } fmt.Printf("%s ", icon) diff --git a/statistics.go b/statistics.go index 0cd7d44..46e89c1 100644 --- a/statistics.go +++ b/statistics.go @@ -1,32 +1,32 @@ package main import ( + "fmt" "os" "path/filepath" "syscall" "time" - "fmt" ) type statistics struct { - Name string; - Type string; //formula or cask - Desc string; - Outdated bool; + Name string + Type string //formula or cask + Desc string + Outdated bool - InstalledAsDependency bool; - InstalledOnRequest bool; - BinaryExists bool; - LastAccessTime time.Time; + InstalledAsDependency bool + InstalledOnRequest bool + BinaryExists bool + LastAccessTime time.Time - InstalledVersion string; - Homepage string; - License string; + InstalledVersion string + Homepage string + License string - ReverseDependencies []string; + ReverseDependencies []string } -func NewStatistics(formula *FormulaInfo, cask *CaskInfo, pkgName string) (*statistics) { +func NewStatistics(formula *FormulaInfo, cask *CaskInfo, pkgName string) *statistics { var statObject statistics // === formula/cask specific === // |
