UPDATE: update new language patch
This commit is contained in:
@@ -4,11 +4,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BinaryVersion struct {
|
||||
Name string
|
||||
Major int
|
||||
Minor int
|
||||
Patch int
|
||||
@@ -22,42 +24,47 @@ func ParseBinaryVersion(path string) (*BinaryVersion, error) {
|
||||
|
||||
content := string(data)
|
||||
|
||||
dashPos := strings.LastIndex(content, "-")
|
||||
if dashPos == -1 {
|
||||
lastDash := strings.LastIndex(content, "-")
|
||||
if lastDash == -1 {
|
||||
return nil, errors.New("no dash found in version string")
|
||||
}
|
||||
|
||||
start := dashPos - 6
|
||||
if start < 0 {
|
||||
start = 0
|
||||
|
||||
secondLastDash := strings.LastIndex(content[:lastDash], "-")
|
||||
if secondLastDash == -1 {
|
||||
return nil, errors.New("only one dash found in version string")
|
||||
}
|
||||
|
||||
versionSlice := content[start:]
|
||||
end := strings.Index(versionSlice, "-")
|
||||
if end == -1 {
|
||||
end = len(versionSlice)
|
||||
}
|
||||
|
||||
versionStr := versionSlice[:end]
|
||||
parts := strings.SplitN(versionStr, ".", 3)
|
||||
if len(parts) != 3 {
|
||||
versionSlice := content[secondLastDash+1 : lastDash]
|
||||
re := regexp.MustCompile(`^([A-Za-z]+)([\d\.]+)$`)
|
||||
matches := re.FindStringSubmatch(versionSlice)
|
||||
if len(matches) < 3 {
|
||||
return nil, errors.New("invalid version format")
|
||||
}
|
||||
binaryVersion := BinaryVersion{
|
||||
Name: matches[1],
|
||||
}
|
||||
numbers := strings.Split(matches[2], ".")
|
||||
|
||||
major, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(numbers) > 0 {
|
||||
binaryVersion.Major, err = strconv.Atoi(numbers[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
minor, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(numbers) > 1 {
|
||||
binaryVersion.Minor, err = strconv.Atoi(numbers[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
patch, err := strconv.Atoi(parts[2])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(numbers) > 2 {
|
||||
binaryVersion.Patch, err = strconv.Atoi(numbers[2])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &BinaryVersion{major, minor, patch}, nil
|
||||
return &binaryVersion, nil
|
||||
}
|
||||
|
||||
func (v *BinaryVersion) String() string {
|
||||
|
||||
Reference in New Issue
Block a user