github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/command/api_version_warning.go (about) 1 package command 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 5 "code.cloudfoundry.org/cli/version" 6 "github.com/blang/semver" 7 ) 8 9 type APIVersionTooHighError struct{} 10 11 func (a APIVersionTooHighError) Error() string { 12 return "" 13 } 14 15 func WarnIfCLIVersionBelowAPIDefinedMinimum(config Config, apiVersion string, ui UI) error { 16 minVer := config.MinCLIVersion() 17 currentVer := config.BinaryVersion() 18 19 isOutdated, err := CheckVersionOutdated(currentVer, minVer) 20 if err != nil { 21 return err 22 } 23 24 if isOutdated { 25 ui.DisplayWarning("Cloud Foundry API version {{.APIVersion}} requires CLI version {{.MinCLIVersion}}. You are currently on version {{.BinaryVersion}}. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", 26 map[string]interface{}{ 27 "APIVersion": apiVersion, 28 "MinCLIVersion": minVer, 29 "BinaryVersion": currentVer, 30 }) 31 } 32 33 return nil 34 } 35 36 func WarnIfAPIVersionBelowSupportedMinimum(apiVersion string, ui UI) error { 37 isOutdated, err := CheckVersionOutdated(apiVersion, ccversion.MinSupportedV2ClientVersion) 38 if err != nil { 39 return err 40 } 41 42 if isOutdated { 43 ui.DisplayWarning("Your CF API version ({{.APIVersion}}) is no longer supported. "+ 44 "Upgrade to a newer version of the API (minimum version {{.MinSupportedVersion}}). Please refer to "+ 45 "https://github.com/cloudfoundry/cli/wiki/Versioning-Policy#cf-cli-minimum-supported-version", 46 map[string]interface{}{ 47 "APIVersion": apiVersion, 48 "MinSupportedVersion": ccversion.MinSupportedV2ClientVersion, 49 }) 50 } 51 52 return nil 53 } 54 55 func CheckVersionOutdated(current string, minimum string) (bool, error) { 56 if current == version.DefaultVersion || minimum == "" { 57 return false, nil 58 } 59 60 currentSemver, err := semver.Make(current) 61 if err != nil { 62 return false, err 63 } 64 65 minimumSemver, err := semver.Make(minimum) 66 if err != nil { 67 return false, err 68 } 69 70 if currentSemver.Compare(minimumSemver) == -1 { 71 return true, nil 72 } 73 74 return false, nil 75 }