diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-10 12:37:16 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-10 12:37:16 +0800 |
| commit | 72acc4fad20ccce95ef775f862c13f29719f12ca (patch) | |
| tree | 4565d8b559a65f0a94ed2a22ebab007520f0c8ad /main.go | |
initial commit
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "github.com/fatih/color" +) + +func main() { + // Check if Homebrew is installed + _, brewInstallationErr := exec.LookPath("brew") + if brewInstallationErr != nil { + color.Red("🍺 Homebrew not installed.") + fmt.Println("This tool is for looking up formulaermation about packages installed with Homebrew. If you don't have Homebrew, it's no use.") + os.Exit(1) + } + + args := os.Args + // handle arguments + var printUsage = func() { + color.New(color.FgBlue).Print("Usage: ") + fmt.Print("wtfis <package>\n") + } + if len(args) < 2 { + printUsage() + os.Exit(1) + } + if args[1] == "-h" || args[1] == "--help" { + printUsage() + os.Exit(0) + } + pkg := args[1] + + // look up formulae + out, brewLookupError := exec.Command("brew", "formulae", "--json=v2", pkg).Output() + if brewLookupError != nil { + fmt.Println("🍺 Homebrew Error:", string(out)) + os.Exit(1) + } + + // parse formulae + var formulae, cask, getformulaeErr = GetInfo(pkg) + if getformulaeErr != nil { + fmt.Println("Error:", getformulaeErr) + os.Exit(1) + } + + PrintInfo(formulae, cask, pkg) +} |
