-
Notifications
You must be signed in to change notification settings - Fork 22
/
consul.go
57 lines (48 loc) · 1.32 KB
/
consul.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
package product
import (
"context"
"fmt"
"os/exec"
"regexp"
"runtime"
"strings"
"github.com/hashicorp/go-version"
"github.com/hashicorp/hc-install/internal/build"
)
var consulVersionOutputRe = regexp.MustCompile(`Consul ` + simpleVersionRe)
var (
v1_16 = version.Must(version.NewVersion("1.16"))
// TODO: version.MustConstraint() ?
v1_16c, _ = version.NewConstraint("1.16")
)
var Consul = Product{
Name: "consul",
BinaryName: func() string {
if runtime.GOOS == "windows" {
return "consul.exe"
}
return "consul"
},
GetVersion: func(ctx context.Context, path string) (*version.Version, error) {
cmd := exec.CommandContext(ctx, path, "version")
out, err := cmd.Output()
if err != nil {
return nil, err
}
stdout := strings.TrimSpace(string(out))
submatches := consulVersionOutputRe.FindStringSubmatch(stdout)
if len(submatches) != 2 {
return nil, fmt.Errorf("unexpected number of version matches %d for %s", len(submatches), stdout)
}
v, err := version.NewVersion(submatches[1])
if err != nil {
return nil, fmt.Errorf("unable to parse version %q: %w", submatches[1], err)
}
return v, err
},
BuildInstructions: &BuildInstructions{
GitRepoURL: "https://github.com/hashicorp/consul.git",
PreCloneCheck: &build.GoIsInstalled{},
Build: &build.GoBuild{Version: v1_16},
},
}