2018-07-04 15:43:52 +03:00
|
|
|
package version
|
|
|
|
|
|
|
|
const (
|
|
|
|
untaggedBuild = "for untagged builds, server and cli versions should match"
|
|
|
|
taggedBuild = "cli version (major.minor) should be equal or ahead of server version, please update cli"
|
|
|
|
noServerVersion = "server with no version treated as pre-release build"
|
|
|
|
noCLIVersion = "cli version is empty, indicates a broken build"
|
|
|
|
untaggedCLI = "untagged cli build can work with tagged server build"
|
2019-01-28 16:55:28 +03:00
|
|
|
devCLI = "dev version of cli, compatible with all servers"
|
2018-07-04 15:43:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// CheckCLIServerCompatibility compares server and cli for compatibility,
|
|
|
|
// subject to certain conditions. compatible boolean is returned along with
|
|
|
|
// a message which states the reason for the result.
|
|
|
|
func (v *Version) CheckCLIServerCompatibility() (compatible bool, reason string) {
|
2019-01-28 16:55:28 +03:00
|
|
|
// mark dev builds as compatible
|
|
|
|
if v.CLI == "dev" {
|
|
|
|
return true, devCLI
|
|
|
|
}
|
2018-07-04 15:43:52 +03:00
|
|
|
// empty cli version
|
|
|
|
if v.CLI == "" {
|
|
|
|
return false, noCLIVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty server version
|
|
|
|
if v.Server == "" {
|
|
|
|
return true, noServerVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
// untagged server version
|
|
|
|
if v.Server != "" && v.ServerSemver == nil {
|
|
|
|
// same cli version
|
|
|
|
if v.CLI == v.Server {
|
|
|
|
return true, untaggedBuild
|
|
|
|
}
|
|
|
|
// different cli version
|
|
|
|
return false, untaggedBuild
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// tagged server version
|
|
|
|
if v.Server != "" && v.ServerSemver != nil {
|
|
|
|
// cli is also tagged build
|
|
|
|
if v.CLI != "" && v.CLISemver != nil {
|
2018-08-30 13:44:07 +03:00
|
|
|
if (v.CLISemver.Major() >= v.ServerSemver.Major()) && (v.CLISemver.Minor() >= v.ServerSemver.Minor()) {
|
2018-07-04 15:43:52 +03:00
|
|
|
return true, taggedBuild
|
|
|
|
}
|
|
|
|
return false, taggedBuild
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// untagged cli version
|
|
|
|
if v.CLI != "" && v.CLISemver == nil {
|
|
|
|
return true, untaggedCLI
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, "versions are incompatible"
|
|
|
|
}
|