mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
bb63d7e60e
Co-authored-by: Rishichandra Wawhal <rishichandra.wawhal@gmail.com> Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Co-authored-by: Aravind <aravindkp@outlook.in> Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com> Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
// 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
|
|
}
|