Load Vagrantfile for basis and project

This commit is contained in:
sophia 2021-05-12 11:46:01 -05:00 committed by Paul Hinze
parent 3b6766cfc1
commit 61ba8c356e
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 45 additions and 0 deletions

View File

@ -107,6 +107,9 @@ func New(ctx context.Context, opts ...Option) (basis *Basis, err error) {
)
if err == nil && result.Found {
basis.basis = result.Basis
if err = basis.LoadVagrantfiles(); err != nil {
return nil, err
}
return basis, nil
}
@ -125,6 +128,10 @@ func New(ctx context.Context, opts ...Option) (basis *Basis, err error) {
}
basis.basis = uresult.Basis
// Find and load Vagrantfiles for the basis
if err = basis.LoadVagrantfiles(); err != nil {
return nil, err
}
return basis, nil
}
@ -143,6 +150,9 @@ func (b *Basis) LoadProject(p *vagrant_server.Project) (*Project, error) {
project: result.Project,
logger: b.logger.Named("project"),
}
if err = b.Project.LoadVagrantfiles(); err != nil {
return nil, err
}
return b.Project, nil
}
@ -166,9 +176,24 @@ func (b *Basis) LoadProject(p *vagrant_server.Project) (*Project, error) {
logger: b.logger.Named("project"),
}
if err = b.Project.LoadVagrantfiles(); err != nil {
return nil, err
}
return b.Project, nil
}
// Finds the Vagrantfile associated with the basis
func (b *Basis) LoadVagrantfiles() error {
_, err := configpkg.FindPath(b.basis.Path, configpkg.GetVagrantfileName())
if err != nil {
return err
}
// TODO:
// 1) Send Vagrantfile found for this basis to the ruby runtime to be parsed
// 2) Upload the Vagrantfile to the vagrant server
return nil
}
func (b *Basis) Ref() *vagrant_plugin_sdk.Ref_Basis {
return &vagrant_plugin_sdk.Ref_Basis{
Name: b.basis.Name,

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/vagrant-plugin-sdk/helper/paths"
vagrant_plugin_sdk "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
configpkg "github.com/hashicorp/vagrant/internal/config"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
)
@ -27,6 +28,18 @@ type Project struct {
logger hclog.Logger
}
// Finds the Vagrantfile associated with the project
func (p *Project) LoadVagrantfiles() error {
_, err := configpkg.FindPath(p.project.Path, configpkg.GetVagrantfileName())
if err != nil {
return err
}
// TODO:
// 1) Send Vagrantfile found for this project to the ruby runtime to be parsed
// 2) Upload the Vagrantfile to the vagrant server
return nil
}
func (p *Project) LoadTarget(t *vagrant_server.Target) (*Target, error) {
target, err := p.GetTarget(t.Name)
if err == nil {

View File

@ -8,6 +8,13 @@ import (
// Filename is the default filename for the Vagrant configuration.
const Filename = "Vagrantfile"
func GetVagrantfileName() string {
if os.Getenv("VAGRANT_VAGRANTFILE") != "" {
return os.Getenv("VAGRANT_VAGRANTFILE")
}
return Filename
}
// FindPath looks for our configuration file starting at "start" and
// traversing parent directories until it is found. If it is found, the
// path is returned. If it is not found, an empty string is returned.