forked from ignite/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmosver.go
101 lines (80 loc) · 1.97 KB
/
cosmosver.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cosmosver
import (
"fmt"
"strings"
)
const (
// Launchpad points to Launchpad version of Cosmos-SDK.
Launchpad MajorVersion = "launchpad"
// Stargate points to Stargate version of Cosmos-SDK.
Stargate MajorVersion = "stargate"
)
const (
LaunchpadAny Version = iota
StargateBelowZeroFourty
StargateZeroFourtyAndAbove
)
// MajorVersions are the list of supported Cosmos-SDK major versions.
var (
MajorVersions = majorVersions{
Launchpad,
Stargate,
}
Versions = versions{
LaunchpadAny,
StargateBelowZeroFourty,
StargateZeroFourtyAndAbove,
}
)
// MajorVersion represents major, named versions of Cosmos-SDK.
type MajorVersion string
func (v MajorVersion) Is(comparedTo MajorVersion) bool {
return v == comparedTo
}
// Version represents a range of Cosmos-SDK versions.
type Version int
func (v Version) Is(comparedTo Version) bool {
return v == comparedTo
}
// Major returns the MajorVersion of the version.
func (v Version) Major() MajorVersion {
switch v {
case StargateBelowZeroFourty, StargateZeroFourtyAndAbove:
return Stargate
default:
return Launchpad
}
}
func (v Version) String() string {
switch v {
case StargateZeroFourtyAndAbove:
return "Stargate v0.40.0 (or above)"
case StargateBelowZeroFourty:
return "Stargate v0.40.0 (pre-release)"
default:
return "Launchpad"
}
}
type majorVersions []MajorVersion
// Parse checks if vs is a supported sdk version for scaffolding and if so,
// it parses it to sdkVersion.
func (v majorVersions) Parse(vs string) (MajorVersion, error) {
for _, version := range v {
if MajorVersion(vs) == version {
return MajorVersion(vs), nil
}
}
return "", fmt.Errorf("%q is an unknown sdk version", vs)
}
// String returns a string representation of the version list.
func (v majorVersions) String() string {
var vs string
for _, version := range v {
vs += " -" + string(version)
}
return strings.TrimSpace(vs)
}
type versions []Version
func (v versions) Latest() Version {
return v[len(v)-1]
}