diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..57a4ac4 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/koding/vagrantutil + +go 1.14 + +require ( + github.com/hashicorp/go-version v1.2.1 + github.com/koding/logging v0.0.0-20160720134017-8b5a689ed69b +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d7d3519 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= +github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/koding/logging v0.0.0-20160720134017-8b5a689ed69b h1:Ix1hwcOtW6e0KG1+Fn1blMih1O4td/fa9Q2Br0/zPBo= +github.com/koding/logging v0.0.0-20160720134017-8b5a689ed69b/go.mod h1:km9Clt+22fAbEvoPJSRufXDN110ZA6xLNU7oe4dwRHk= diff --git a/parse_test.go b/parse_test.go index b152b58..e2c97aa 100644 --- a/parse_test.go +++ b/parse_test.go @@ -38,7 +38,7 @@ func TestParseRecordsAndData(t *testing.T) { } if ver != cas.ver { - t.Errorf("%d: got %q, want %q", ver, cas.ver) + t.Errorf("%d: got %q, want %q", i, ver, cas.ver) } } } diff --git a/vagrant.go b/vagrant.go index ca5b24f..afff560 100644 --- a/vagrant.go +++ b/vagrant.go @@ -228,15 +228,41 @@ func (v *Vagrant) List() ([]*Vagrant, error) { return boxes, nil } +// Provision executes "vagrant provision" for the given vagrantfile. The returned channel +// contains the output stream. At the end of the output, the error is put into +// the Error field if there is any. +func (v *Vagrant) Provision() (<-chan *CommandOutput, error) { + if v.ProviderName != "" { + return v.vagrantCommand().start("provision", "--provider", v.ProviderName) + } + + return v.vagrantCommand().start("provision") +} + +// VagrantOption is a generic interface that all options to vagrant commands implement +type VagrantOption interface {} + +// VagrantOptionProvision forces re-provisioning of the vagrant machine +type VagrantOptionProvision struct { + VagrantOption +} + // Up executes "vagrant up" for the given vagrantfile. The returned channel // contains the output stream. At the end of the output, the error is put into // the Error field if there is any. -func (v *Vagrant) Up() (<-chan *CommandOutput, error) { +func (v *Vagrant) Up(opts ...VagrantOption) (<-chan *CommandOutput, error) { + args := []string{"up"} if v.ProviderName != "" { - return v.vagrantCommand().start("up", "--provider", v.ProviderName) + args = append(args, []string{"--provider", v.ProviderName}...) } + for _, opt := range opts { + switch opt.(type) { + case VagrantOptionProvision: + args = append(args, "--provision") + } + } - return v.vagrantCommand().start("up") + return v.vagrantCommand().start(args...) } // Halt executes "vagrant halt". The returned reader contains the output