ajhahn.de
← eeco
Go 35 lines
package selfupdate

import (
	"strings"
)

// detectPackageManager returns a short label and a one-line operator
// hint when the running binary appears to live under a known package-
// manager prefix. Heuristic-only — we never rewrite a brew-managed or
// scoop-managed install. Empty kind means "unknown / hand-installed."
//
// The check works off the running path verbatim with backslashes
// normalised to slashes (filepath.ToSlash only swaps separators on
// Windows; an explicit ReplaceAll keeps the check platform-independent
// so a Windows-style fixture path tests the same on every host). We
// deliberately skip filepath.Abs — calling it on Windows would prepend
// a drive letter to a Unix-style test fixture and break the prefix
// match.
func detectPackageManager(running string) (kind, hint string) {
	low := strings.ToLower(strings.ReplaceAll(running, `\`, "/"))

	switch {
	case strings.Contains(low, "/cellar/eeco/"),
		strings.HasPrefix(low, "/opt/homebrew/"),
		strings.HasPrefix(low, "/home/linuxbrew/.linuxbrew/"),
		strings.HasPrefix(low, "/usr/local/cellar/"):
		return "Homebrew", "use 'brew upgrade eeco' instead"
	case strings.Contains(low, "/.linuxbrew/"):
		return "Homebrew", "use 'brew upgrade eeco' instead"
	case strings.Contains(low, "/scoop/apps/eeco/"):
		return "Scoop", "use 'scoop update eeco' instead"
	}
	return "", ""
}