Files
snack/apk/normalize.go
Tai Groot 934c6610c5 feat: add Homebrew provider, implement NameNormalizer across all managers
- Add brew package for Homebrew support on macOS and Linux
- Implement NameNormalizer interface (NormalizeName, ParseArch) for all providers
- Add darwin platform detection with Homebrew as default
- Consolidate capabilities by removing separate *_linux.go/*_other.go files
- Update tests for new capability expectations
- Add comprehensive tests for AUR and brew providers
- Update README with capability matrix and modern Target API usage

💘 Generated with Crush

Assisted-by: AWS Claude Opus 4.5 via Crush <crush@charm.land>
2026-03-05 20:40:32 -05:00

39 lines
990 B
Go

package apk
import "strings"
// normalizeName returns the canonical form of a package name.
// Alpine package names sometimes include version suffixes in queries.
// This strips common version patterns.
func normalizeName(name string) string {
n, _ := parseArchNormalize(name)
return n
}
// parseArchNormalize extracts the architecture from a package name if present.
// Alpine package names typically don't embed architecture in the package name,
// but some query outputs may include it. Common patterns:
// - package-x86_64
// - package-aarch64
func parseArchNormalize(name string) (string, string) {
knownArchs := map[string]bool{
"x86_64": true,
"x86": true,
"aarch64": true,
"armhf": true,
"armv7": true,
"ppc64le": true,
"s390x": true,
"riscv64": true,
"loongarch64": true,
}
if idx := strings.LastIndex(name, "-"); idx >= 0 {
suffix := name[idx+1:]
if knownArchs[suffix] {
return name[:idx], suffix
}
}
return name, ""
}