From af07603178b6fca272106a941fdac87c957f7766 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Wed, 19 Dec 2018 16:57:11 +0200 Subject: [PATCH] version: add 3 methods Added WithMajor, WithMinor, WithPatch and WithPreRelease methods to the Version API. These methods return copy of the Version object with one changed property(Major, Minor, Patch or preRelease). --- .../apimachinery/pkg/util/version/version.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/version/version.go b/staging/src/k8s.io/apimachinery/pkg/util/version/version.go index 24724e50ac5..9bc928a4e82 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/version/version.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/version/version.go @@ -154,6 +154,35 @@ func (v *Version) Components() []uint { return v.components } +// WithMajor returns copy of the version object with requested major number +func (v *Version) WithMajor(major uint) *Version { + result := *v + result.components = []uint{major, v.Minor(), v.Patch()} + return &result +} + +// WithMinor returns copy of the version object with requested minor number +func (v *Version) WithMinor(minor uint) *Version { + result := *v + result.components = []uint{v.Major(), minor, v.Patch()} + return &result +} + +// WithPatch returns copy of the version object with requested patch number +func (v *Version) WithPatch(patch uint) *Version { + result := *v + result.components = []uint{v.Major(), v.Minor(), patch} + return &result +} + +// WithPreRelease returns copy of the version object with requested prerelease +func (v *Version) WithPreRelease(preRelease string) *Version { + result := *v + result.components = []uint{v.Major(), v.Minor(), v.Patch()} + result.preRelease = preRelease + return &result +} + // String converts a Version back to a string; note that for versions parsed with // ParseGeneric, this will not include the trailing uninterpreted portion of the version // number.