mirror of https://github.com/docker/cli.git
Merge pull request #2159 from thaJeztah/bump_go_version
bump hashicorp/go-version v1.2.0
This commit is contained in:
commit
01a8d2c2c4
|
@ -40,7 +40,7 @@ github.com/googleapis/gnostic 7c663266750e7d82587642f65e60
|
||||||
github.com/gorilla/mux ed099d42384823742bba0bf9a72b53b55c9e2e38 # v1.7.2
|
github.com/gorilla/mux ed099d42384823742bba0bf9a72b53b55c9e2e38 # v1.7.2
|
||||||
github.com/grpc-ecosystem/grpc-gateway 1a03ca3bad1e1ebadaedd3abb76bc58d4ac8143b
|
github.com/grpc-ecosystem/grpc-gateway 1a03ca3bad1e1ebadaedd3abb76bc58d4ac8143b
|
||||||
github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
|
github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
|
||||||
github.com/hashicorp/go-version 23480c0665776210b5fbbac6eaaee40e3e6a96b7
|
github.com/hashicorp/go-version ac23dc3fea5d1a983c43f6a0f6e2c13f0195d8bd # v1.2.0
|
||||||
github.com/hashicorp/golang-lru 0fb14efe8c47ae851c0034ed7a448854d3d34cf3
|
github.com/hashicorp/golang-lru 0fb14efe8c47ae851c0034ed7a448854d3d34cf3
|
||||||
github.com/imdario/mergo 7c29201646fa3de8506f701213473dd407f19646 # v0.3.7
|
github.com/imdario/mergo 7c29201646fa3de8506f701213473dd407f19646 # v0.3.7
|
||||||
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0.0
|
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0.0
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
module github.com/hashicorp/go-version
|
|
@ -10,14 +10,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// The compiled regular expression used to test the validity of a version.
|
// The compiled regular expression used to test the validity of a version.
|
||||||
var versionRegexp *regexp.Regexp
|
var (
|
||||||
|
versionRegexp *regexp.Regexp
|
||||||
|
semverRegexp *regexp.Regexp
|
||||||
|
)
|
||||||
|
|
||||||
// The raw regular expression string used for testing the validity
|
// The raw regular expression string used for testing the validity
|
||||||
// of a version.
|
// of a version.
|
||||||
const VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
|
const (
|
||||||
`(-?([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
|
VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
|
||||||
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
|
`(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
|
||||||
`?`
|
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
|
||||||
|
`?`
|
||||||
|
|
||||||
|
// SemverRegexpRaw requires a separator between version and prerelease
|
||||||
|
SemverRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
|
||||||
|
`(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
|
||||||
|
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
|
||||||
|
`?`
|
||||||
|
)
|
||||||
|
|
||||||
// Version represents a single version.
|
// Version represents a single version.
|
||||||
type Version struct {
|
type Version struct {
|
||||||
|
@ -25,16 +36,29 @@ type Version struct {
|
||||||
pre string
|
pre string
|
||||||
segments []int64
|
segments []int64
|
||||||
si int
|
si int
|
||||||
|
original string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$")
|
versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$")
|
||||||
|
semverRegexp = regexp.MustCompile("^" + SemverRegexpRaw + "$")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVersion parses the given version and returns a new
|
// NewVersion parses the given version and returns a new
|
||||||
// Version.
|
// Version.
|
||||||
func NewVersion(v string) (*Version, error) {
|
func NewVersion(v string) (*Version, error) {
|
||||||
matches := versionRegexp.FindStringSubmatch(v)
|
return newVersion(v, versionRegexp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSemver parses the given version and returns a new
|
||||||
|
// Version that adheres strictly to SemVer specs
|
||||||
|
// https://semver.org/
|
||||||
|
func NewSemver(v string) (*Version, error) {
|
||||||
|
return newVersion(v, semverRegexp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newVersion(v string, pattern *regexp.Regexp) (*Version, error) {
|
||||||
|
matches := pattern.FindStringSubmatch(v)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
return nil, fmt.Errorf("Malformed version: %s", v)
|
return nil, fmt.Errorf("Malformed version: %s", v)
|
||||||
}
|
}
|
||||||
|
@ -59,11 +83,17 @@ func NewVersion(v string) (*Version, error) {
|
||||||
segments = append(segments, 0)
|
segments = append(segments, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre := matches[7]
|
||||||
|
if pre == "" {
|
||||||
|
pre = matches[4]
|
||||||
|
}
|
||||||
|
|
||||||
return &Version{
|
return &Version{
|
||||||
metadata: matches[7],
|
metadata: matches[10],
|
||||||
pre: matches[4],
|
pre: pre,
|
||||||
segments: segments,
|
segments: segments,
|
||||||
si: si,
|
si: si,
|
||||||
|
original: v,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +112,7 @@ func Must(v *Version, err error) *Version {
|
||||||
// or larger than the other version, respectively.
|
// or larger than the other version, respectively.
|
||||||
//
|
//
|
||||||
// If you want boolean results, use the LessThan, Equal,
|
// If you want boolean results, use the LessThan, Equal,
|
||||||
// or GreaterThan methods.
|
// GreaterThan, GreaterThanOrEqual or LessThanOrEqual methods.
|
||||||
func (v *Version) Compare(other *Version) int {
|
func (v *Version) Compare(other *Version) int {
|
||||||
// A quick, efficient equality check
|
// A quick, efficient equality check
|
||||||
if v.String() == other.String() {
|
if v.String() == other.String() {
|
||||||
|
@ -258,11 +288,21 @@ func (v *Version) GreaterThan(o *Version) bool {
|
||||||
return v.Compare(o) > 0
|
return v.Compare(o) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GreaterThanOrEqualTo tests if this version is greater than or equal to another version.
|
||||||
|
func (v *Version) GreaterThanOrEqual(o *Version) bool {
|
||||||
|
return v.Compare(o) >= 0
|
||||||
|
}
|
||||||
|
|
||||||
// LessThan tests if this version is less than another version.
|
// LessThan tests if this version is less than another version.
|
||||||
func (v *Version) LessThan(o *Version) bool {
|
func (v *Version) LessThan(o *Version) bool {
|
||||||
return v.Compare(o) < 0
|
return v.Compare(o) < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LessThanOrEqualTo tests if this version is less than or equal to another version.
|
||||||
|
func (v *Version) LessThanOrEqual(o *Version) bool {
|
||||||
|
return v.Compare(o) <= 0
|
||||||
|
}
|
||||||
|
|
||||||
// Metadata returns any metadata that was part of the version
|
// Metadata returns any metadata that was part of the version
|
||||||
// string.
|
// string.
|
||||||
//
|
//
|
||||||
|
@ -301,11 +341,19 @@ func (v *Version) Segments() []int {
|
||||||
// for a version "1.2.3-beta", segments will return a slice of
|
// for a version "1.2.3-beta", segments will return a slice of
|
||||||
// 1, 2, 3.
|
// 1, 2, 3.
|
||||||
func (v *Version) Segments64() []int64 {
|
func (v *Version) Segments64() []int64 {
|
||||||
return v.segments
|
result := make([]int64, len(v.segments))
|
||||||
|
copy(result, v.segments)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the full version string included pre-release
|
// String returns the full version string included pre-release
|
||||||
// and metadata information.
|
// and metadata information.
|
||||||
|
//
|
||||||
|
// This value is rebuilt according to the parsed segments and other
|
||||||
|
// information. Therefore, ambiguities in the version string such as
|
||||||
|
// prefixed zeroes (1.04.0 => 1.4.0), `v` prefix (v1.0.0 => 1.0.0), and
|
||||||
|
// missing parts (1.0 => 1.0.0) will be made into a canonicalized form
|
||||||
|
// as shown in the parenthesized examples.
|
||||||
func (v *Version) String() string {
|
func (v *Version) String() string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
fmtParts := make([]string, len(v.segments))
|
fmtParts := make([]string, len(v.segments))
|
||||||
|
@ -324,3 +372,9 @@ func (v *Version) String() string {
|
||||||
|
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Original returns the original parsed version as-is, including any
|
||||||
|
// potential whitespace, `v` prefix, etc.
|
||||||
|
func (v *Version) Original() string {
|
||||||
|
return v.original
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue