swadhinbiswas feat: live scan matrix, safety vacuuming & theme engine · 8/17/2026
ba4f98c
46 lines · 979 Bytes
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 detector

import (
	"context"
	"strings"

	"github.com/swadhinbiswas/veet/internal/model"
)

type brewDetector struct {
	ex   Execer
	path string
}

// NewBrewDetector detects Homebrew formulae and casks on Linux.
func NewBrewDetector(ex Execer) Detector {
	path, _ := ex.LookPath("brew")
	return &brewDetector{ex: ex, path: path}
}

func (d *brewDetector) Source() string  { return "brew" }
func (d *brewDetector) Available() bool { return d.path != "" }

func (d *brewDetector) Detect(ctx context.Context) ([]model.AppInfo, error) {
	out, err := Exec(ctx, d.ex, "brew", "list", "--versions")
	if err != nil {
		return nil, err
	}
	var apps []model.AppInfo
	for _, line := range strings.Split(out, "\n") {
		fields := strings.Fields(line)
		if len(fields) < 2 {
			continue
		}
		name := fields[0]
		version := fields[1]
		apps = append(apps, model.AppInfo{
			Name:    name,
			Version: version,
			Source:  "brew",
			Status:  "Installed",
		})
	}
	return apps, nil
}