Files
Michael BiancoandGitHub 3fee1b57cd refactor: update to go 1.21+ syntax and idioms (#524)
* refactor: update to go 1.21+ syntax and idioms

- Replace interface{} with any throughout the codebase.
- Use strings.SplitSeq and strings.CutPrefix for more efficient string processing.
- Utilize slices.Contains for cleaner slice membership checks.
- Use strings.Builder for efficient string concatenation.
- Adopt modern loop syntax (for range) for iteration.
- Remove redundant omitempty tags in struct definitions.

Generated-by: aiautocommit

* refactor: linting fix

* build: standardize commit messages for automation tasks

- Update commit messages in the upgrade task to follow conventional commit standards.
- Ensure consistency across automated fix, formatting, and snapshot update processes.

Generated-by: aiautocommit

* refactor: update commit messages in mise-upgrade task

Generated-by: aiautocommit
2026-03-23 08:07:06 -06:00

48 lines
1.2 KiB
Go

package resolver
import "strings"
func resolveToFuzzyVersion(version string) string {
// Remove any whitespace
version = strings.TrimSpace(version)
// Handle empty string and "*" cases
if version == "" || version == "*" {
return "latest"
}
// Handle range notation (e.g. ">=22 <23" or ">= 22" or ">=20.0.0")
if strings.Contains(version, ">=") || strings.Contains(version, "<") {
parts := strings.Fields(version)
for i, part := range parts {
if after, ok := strings.CutPrefix(part, ">="); ok {
// Version number is either after the >= in this part, or in the next part
v := after
if v == "" && i+1 < len(parts) {
v = parts[i+1]
}
return strings.Split(strings.TrimSpace(v), ".")[0]
}
}
}
// Handle caret notation by only keeping major version
if after, ok := strings.CutPrefix(version, "^"); ok {
version = after
parts := strings.Split(version, ".")
return parts[0]
}
// Remove any prefix characters (~, v)
version = strings.TrimPrefix(version, "~")
version = strings.TrimPrefix(version, "v")
// Replace .x with empty string (e.g. "14.x" -> "14")
version = strings.ReplaceAll(version, ".x", "")
// Remove any trailing dots
version = strings.TrimRight(version, ".")
return version
}