summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-11 10:44:40 +0800
committerEltrac <hi@guhub.cn>2025-11-11 10:44:40 +0800
commit7487402fb90a3411b23749d489f58f22b24499f6 (patch)
tree9f71a513bf09af5cd5d9e4460b85fba5665d9e12
parent01785b30016779e46d90febc421e22a3d7e32b9e (diff)
style(info.go): handle error internally
-rw-r--r--info.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/info.go b/info.go
index 17b6b13..cfc80f0 100644
--- a/info.go
+++ b/info.go
@@ -5,6 +5,7 @@ import (
"os/exec"
"strings"
"bytes"
+ "github.com/fatih/color"
)
type FormulaInfo struct {
@@ -36,10 +37,11 @@ type CaskInfo struct {
// GetInfo fetches package info for both formulae and casks.
// It returns one of the two structs depending on the package type.
-func GetInfo(pkg string) (*FormulaInfo, *CaskInfo, error) {
+func GetInfo(pkg string) (*FormulaInfo, *CaskInfo) {
out, err := exec.Command("brew", "info", "--json=v2", pkg).Output()
if err != nil {
- return nil, nil, err
+ color.Red("❌ Error fetching info. Please check for typo.")
+ return nil, nil
}
var data struct {
@@ -48,17 +50,18 @@ func GetInfo(pkg string) (*FormulaInfo, *CaskInfo, error) {
}
if err := json.Unmarshal(out, &data); err != nil {
- return nil, nil, err
+ color.Red("❌ Error parsing data.")
+ return nil, nil
}
if len(data.Formulae) > 0 {
- return &data.Formulae[0], nil, nil
+ return &data.Formulae[0], nil
}
if len(data.Casks) > 0 {
- return nil, &data.Casks[0], nil
+ return nil, &data.Casks[0]
}
- return nil, nil, nil // not found
+ return nil, nil // not found
}
func GetReverseDependencies(pkg string) ([]string, error) {