summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-11 19:32:34 +0800
committerEltrac <hi@guhub.cn>2025-11-11 19:32:34 +0800
commiteb5d4249c6db97bbbb52fd86c1451be50bb33398 (patch)
treee783bec52b0cea2a216671b211d432f34e3764f5
parent085a48a39702e2fed1f771c3fb23c062704957e4 (diff)
fix: make sure to exit when certain error occurs
-rw-r--r--brewget.go6
-rw-r--r--main.go10
2 files changed, 9 insertions, 7 deletions
diff --git a/brewget.go b/brewget.go
index 202e985..4edcfc0 100644
--- a/brewget.go
+++ b/brewget.go
@@ -40,8 +40,7 @@ type CaskInfo struct {
func GetBrewInfo(pkg string) (*FormulaInfo, *CaskInfo) {
out, err := exec.Command("brew", "info", "--json=v2", pkg).Output()
if err != nil {
- color.Red("❌ Error fetching info. Please check for typo.")
- return nil, nil
+ printErrorAndExit("Error fetching info. Please check for typo.")
}
var data struct {
@@ -50,8 +49,7 @@ func GetBrewInfo(pkg string) (*FormulaInfo, *CaskInfo) {
}
if err := json.Unmarshal(out, &data); err != nil {
- color.Red("❌ Error parsing data.")
- return nil, nil
+ printErrorAndExit("Error parsing data.")
}
if len(data.Formulae) > 0 {
diff --git a/main.go b/main.go
index 5b7147c..352517c 100644
--- a/main.go
+++ b/main.go
@@ -19,9 +19,7 @@ func main() {
Action: func(ctx context.Context, cmd *cli.Command) error {
// check args
if cmd.Args().Len() == 0 {
- color.Red("❌ Please provide a formulae/cask name.")
- fmt.Println("Usage: wthis <name>")
- return nil
+ printErrorAndExit("Please provide a formulae/cask name.")
}
pkgName := cmd.Args().First()
// prompt
@@ -40,3 +38,9 @@ func main() {
log.Fatal(err)
}
}
+
+func printErrorAndExit(msg string) {
+ hideLoadingPrompt()
+ color.Red("❌ %s", msg)
+ os.Exit(1)
+}