Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vagrant provision #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
32 changes: 29 additions & 3 deletions vagrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down