mirror of
https://git.sr.ht/~eliasnaur/gio-cmd
synced 2026-07-07 02:15:32 +00:00
gogio: support explicit version codes through a fourth version field
As suggested in review, explicitly specifying the version code with -version major.minor.patch.versioncode provides more flexibility than the a version code implied from the major, minor, patch fields. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+4
-11
@@ -33,8 +33,8 @@ type buildInfo struct {
|
||||
}
|
||||
|
||||
type Semver struct {
|
||||
Major uint16
|
||||
Minor, Patch uint8
|
||||
Major, Minor, Patch int
|
||||
VersionCode uint32
|
||||
}
|
||||
|
||||
func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
||||
@@ -83,19 +83,12 @@ func UppercaseName(name string) string {
|
||||
}
|
||||
|
||||
func (s Semver) String() string {
|
||||
return fmt.Sprintf("%d.%d.%d", s.Major, s.Minor, s.Patch)
|
||||
}
|
||||
|
||||
// Version32 returns a 32-bit integer version packed as such:
|
||||
//
|
||||
// major<<16 | minor<<8 | patch
|
||||
func (s Semver) Version32() uint32 {
|
||||
return uint32(s.Major)<<16 | uint32(s.Minor)<<8 | uint32(s.Patch)
|
||||
return fmt.Sprintf("%d.%d.%d.%d", s.Major, s.Minor, s.Patch, s.VersionCode)
|
||||
}
|
||||
|
||||
func parseSemver(v string) (Semver, error) {
|
||||
var sv Semver
|
||||
_, err := fmt.Sscanf(v, "%d.%d.%d", &sv.Major, &sv.Minor, &sv.Patch)
|
||||
_, err := fmt.Sscanf(v, "%d.%d.%d.%d", &sv.Major, &sv.Minor, &sv.Patch, &sv.VersionCode)
|
||||
if err != nil {
|
||||
return Semver{}, fmt.Errorf("invalid semver: %q", v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user