forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
max_api_version.go
58 lines (48 loc) · 1.38 KB
/
max_api_version.go
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
package requirements
import (
"github.com/blang/semver"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
"github.com/cloudfoundry/cli/cf/terminal"
. "github.com/cloudfoundry/cli/cf/i18n"
)
type MaxAPIVersionRequirement struct {
ui terminal.UI
config core_config.Reader
feature string
maximumVersion semver.Version
}
func NewMaxAPIVersionRequirement(
ui terminal.UI,
config core_config.Reader,
feature string,
maximumVersion semver.Version,
) MaxAPIVersionRequirement {
return MaxAPIVersionRequirement{
ui: ui,
config: config,
feature: feature,
maximumVersion: maximumVersion,
}
}
func (r MaxAPIVersionRequirement) Execute() bool {
if r.config.ApiVersion() == "" {
r.ui.Failed(T("Unable to determine CC API Version. Please log in again."))
}
apiVersion, err := semver.Make(r.config.ApiVersion())
if err != nil {
r.ui.Failed(T("Unable to parse CC API Version '{{.APIVersion}}'", map[string]interface{}{
"APIVersion": r.config.ApiVersion(),
}))
return false
}
if apiVersion.GT(r.maximumVersion) {
r.ui.Failed(T(`{{.Feature}} only works up to CF API version {{.MaximumVersion}}. Your target is {{.ApiVersion}}.`,
map[string]interface{}{
"ApiVersion": r.config.ApiVersion(),
"Feature": r.feature,
"MaximumVersion": r.maximumVersion.String(),
}))
return false
}
return true
}