-
Notifications
You must be signed in to change notification settings - Fork 5
/
vagrant_client.go
42 lines (36 loc) · 1020 Bytes
/
vagrant_client.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
package vagrant
import (
"os"
"os/exec"
"path/filepath"
)
// Library users should construct a new VagrantClient using NewVagrantClient().
// From the client, vagrant commands can be constructed such as: client.Up().
type VagrantClient struct {
// Directory where the Vagrantfile can be found.
//
// Normally this would be set by NewVagrantClient() and shouldn't
// be changed afterward.
VagrantfileDir string
executable string
}
// Create a new VagrantClient.
//
// vagrantfileDir should be the path to a directory where the Vagrantfile
// exists.
func NewVagrantClient(vagrantfileDir string) (*VagrantClient, error) {
// Verify the vagrant command is in the path
path, err := exec.LookPath("vagrant")
if err != nil {
return nil, err
}
// Verify a Vagrantfile exists
vagrantfilePath := filepath.Join(vagrantfileDir, "Vagrantfile")
if _, err := os.Stat(vagrantfilePath); err != nil {
return nil, err
}
return &VagrantClient{
VagrantfileDir: vagrantfileDir,
executable: path,
}, nil
}