-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathversion_info.go
63 lines (53 loc) · 1.6 KB
/
version_info.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
package main
import (
"fmt"
"regexp"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/errorutil"
"github.com/bitrise-io/go-utils/log"
)
type flutterVersion struct {
version string
channel string
}
func flutterVersionInfo() (flutterVersion, string, error) {
fmt.Println()
versionCmd := command.New("flutter", "--version")
log.Donef("$ %s", versionCmd.PrintableCommandArgs())
fmt.Println()
out, err := versionCmd.RunAndReturnTrimmedCombinedOutput()
if err != nil {
if errorutil.IsExitStatusError(err) {
return flutterVersion{}, out, fmt.Errorf("failed to get flutter version, error: %s, out: %s", err, out)
}
return flutterVersion{}, "", fmt.Errorf("failed to get flutter version, error: %s", err)
}
channel, err := matchChannel(out)
if err != nil {
return flutterVersion{}, out, err
}
version, err := matchVersion(out)
if err != nil {
return flutterVersion{channel: channel}, out, err
}
return flutterVersion{
channel: channel,
version: version,
}, out, nil
}
func matchVersion(versionOutput string) (string, error) {
versionRegexp := regexp.MustCompile(`(?im)^Flutter\s+(\S+?)\s+`)
submatches := versionRegexp.FindStringSubmatch(versionOutput)
if submatches == nil {
return "", fmt.Errorf("failed to parse flutter version")
}
return submatches[1], nil
}
func matchChannel(versionOutput string) (string, error) {
channelRegexp := regexp.MustCompile(`(?im)\s+channel\s+(\S+?)\s+`)
submatches := channelRegexp.FindStringSubmatch(versionOutput)
if submatches == nil {
return "", fmt.Errorf("failed to parse flutter channel")
}
return submatches[1], nil
}