diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-11 19:32:34 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-11 19:32:34 +0800 |
| commit | eb5d4249c6db97bbbb52fd86c1451be50bb33398 (patch) | |
| tree | e783bec52b0cea2a216671b211d432f34e3764f5 | |
| parent | 085a48a39702e2fed1f771c3fb23c062704957e4 (diff) | |
fix: make sure to exit when certain error occurs
| -rw-r--r-- | brewget.go | 6 | ||||
| -rw-r--r-- | main.go | 10 |
2 files changed, 9 insertions, 7 deletions
@@ -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 { @@ -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) +} |
