Repository navigation
Expand file tree
/
Copy pathversion.go
More file actions
78 lines (65 loc) · 1.92 KB
/
Copy pathversion.go
File metadata and controls
78 lines (65 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Package version implements server, cli and console version handling.
package version
import (
"fmt"
"github.com/Masterminds/semver"
)
// DevVersion is the version string for development versions.
const DevVersion = "dev"
// BuildVersion is the versin string with which CLI is built. Set during
// the build time.
var BuildVersion = DevVersion
// Version defines the version object.
type Version struct {
// CLI is the version of CLI
CLI string
// CLISemver is the parsed semantic version for CLI
CLISemver *semver.Version
// Server is the version of server CLI is interacting with
Server string
// ServerSemver is the parsed semantic version for server
ServerSemver *semver.Version
// ServerFeatureFlags indicates what features are supported by this
// version of server.
ServerFeatureFlags *ServerFeatureFlags
}
// GetCLIVersion return the CLI version string.
func (v *Version) GetCLIVersion() string {
return v.CLI
}
// GetServerVersion return the server version string.
func (v *Version) GetServerVersion() string {
return v.Server
}
// SetCLIVersion parses the version string vs and sets it as CLI version
func (v *Version) SetCLIVersion(s string) {
// if semver parsing fails, cv will be nil
sv, _ := semver.NewVersion(s)
v.CLI = s
if sv != nil {
v.CLI = fmt.Sprintf("v%s", sv.String())
}
v.CLISemver = sv
}
// SetServerVersion parses the version string vs and sets it as server version
func (v *Version) SetServerVersion(s string) {
// if semver parsing fails, sv will be nil
sv, _ := semver.NewVersion(s)
v.Server = s
if sv != nil {
v.Server = fmt.Sprintf("v%s", sv.String())
}
v.ServerSemver = sv
}
// New returns a new version object with BuildVersion filled in as CLI
func New() *Version {
v := &Version{}
v.SetCLIVersion(BuildVersion)
return v
}
// NewCLIVersion returns a new version object with CLI info filled in
func NewCLIVersion(cli string) *Version {
v := &Version{}
v.SetCLIVersion(cli)
return v
}