github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/command/api_version_warning.go (about) 1 package command 2 3 import ( 4 "code.cloudfoundry.org/cli/command/v2/constant" 5 "code.cloudfoundry.org/cli/version" 6 "github.com/blang/semver" 7 ) 8 9 func WarnCLIVersionCheck(config Config, ui UI) error { 10 minVer := config.MinCLIVersion() 11 currentVer := config.BinaryVersion() 12 13 isOutdated, err := checkVersionOutdated(currentVer, minVer) 14 if err != nil { 15 return err 16 } 17 18 if isOutdated { 19 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", 20 map[string]interface{}{ 21 "APIVersion": config.APIVersion(), 22 "MinCLIVersion": minVer, 23 "BinaryVersion": currentVer, 24 }) 25 ui.DisplayNewline() 26 } 27 28 return nil 29 } 30 31 func WarnAPIVersionCheck(apiVersion string, ui UI) error { 32 isOutdated, err := checkVersionOutdated(apiVersion, constant.MinimumAPIVersion) 33 if err != nil { 34 return err 35 } 36 37 if isOutdated { 38 ui.DisplayWarning("Your API version is no longer supported. Upgrade to a newer version of the API.") 39 } 40 41 return nil 42 } 43 44 func checkVersionOutdated(current string, minimum string) (bool, error) { 45 if current == version.DefaultVersion || minimum == "" { 46 return false, nil 47 } 48 49 currentSemvar, err := semver.Make(current) 50 if err != nil { 51 return false, err 52 } 53 54 minimumSemvar, err := semver.Make(minimum) 55 if err != nil { 56 return false, err 57 } 58 59 if currentSemvar.Compare(minimumSemvar) == -1 { 60 return true, nil 61 } 62 63 return false, nil 64 }