blob: 352517cafa68c26bee80d1d86d24c5795a25062b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package main
import (
"fmt"
"os"
"context"
"log"
"github.com/fatih/color"
"github.com/urfave/cli/v3"
)
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 and print
formulae, cask := GetBrewInfo(pkgName)
data := UnifyInfo(formulae, cask, pkgName)
hideLoadingPrompt()
PrintInfo(data)
return nil
},
}
// run command and handle error
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}
func printErrorAndExit(msg string) {
hideLoadingPrompt()
color.Red("❌ %s", msg)
os.Exit(1)
}
|