mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
- Update go.mod from Go 1.26.0 to 1.26.1 - Update dependencies: golang.org/x/sync, golang.org/x/sys, charmbracelet/x/exp/charmtone, mattn/go-runewidth - Fix goimports formatting in 10 files - Add apk/normalize_test.go: tests for normalizeName and parseArchNormalize with all known arch suffixes - Add rpm/parse_test.go: tests for parseList, parseInfo, parseArchSuffix, and normalizeName (all at 100% coverage) - All tests pass with -race, staticcheck and go vet clean
39 lines
1014 B
Go
39 lines
1014 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, ""
|
|
}
|