1package module
2
3import (
4 "cuelang.org/go/internal/mod/semver"
5)
6
7// Versions implements mvs.Versions[Version].
8type Versions struct{}
9
10func (Versions) Version(v Version) string {
11 return v.Version()
12}
13
14func (Versions) Path(v Version) string {
15 return v.Path()
16}
17
18func (Versions) New(p, v string) (Version, error) {
19 return NewVersion(p, v)
20}
21
22// Max implements mvs.Reqs.Max.
23//
24// It is consistent with semver.Compare except that as a special case,
25// the version "" is considered higher than all other versions. The main
26// module (also known as the target) has no version and must be chosen
27// over other versions of the same module in the module dependency
28// graph.
29//
30// See [mvs.Reqs] for more detail.
31func (Versions) Max(v1, v2 string) string {
32 if v1 == "none" || v2 == "" {
33 return v2
34 }
35 if v2 == "none" || v1 == "" {
36 return v1
37 }
38 if semver.Compare(v1, v2) > 0 {
39 return v1
40 }
41 return v2
42}