Get boxes from project

This commit is contained in:
sophia 2021-11-15 09:49:23 -06:00 committed by Paul Hinze
parent a841ca8552
commit 2dfb9b933e
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 26 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package core
import (
"context"
"fmt"
"path/filepath"
"strings"
"sync"
@ -33,15 +34,16 @@ import (
// finished with the basis to properly clean
// up any open resources.
type Basis struct {
basis *vagrant_server.Basis
logger hclog.Logger
config *config.Config
plugins *plugin.Manager
projects map[string]*Project
mappers []*argmapper.Func
dir *datadir.Basis
ctx context.Context
statebag core.StateBag
basis *vagrant_server.Basis
logger hclog.Logger
config *config.Config
plugins *plugin.Manager
projects map[string]*Project
mappers []*argmapper.Func
dir *datadir.Basis
ctx context.Context
statebag core.StateBag
boxCollection *BoxCollection
lookupCache map[string]interface{}
@ -200,6 +202,16 @@ func (b *Basis) State() *StateBag {
return b.statebag.(*StateBag)
}
func (b *Basis) Boxes() (bc *BoxCollection, err error) {
if b.boxCollection == nil {
b.boxCollection = &BoxCollection{
basis: b,
directory: filepath.Join(b.dir.DataDir().String(), "boxes"),
}
}
return b.boxCollection, nil
}
func (b *Basis) countParents(host core.Host) (int, error) {
numParents := 0
p, err := host.Parent()

View File

@ -62,6 +62,11 @@ func (p *Project) UI() (terminal.UI, error) {
return p.ui, nil
}
// Boxes implements core.Project
func (p *Project) Boxes() (bc core.BoxCollection, err error) {
return p.basis.Boxes()
}
// CWD implements core.Project
func (p *Project) CWD() (path string, err error) {
cwd, ok := os.LookupEnv("VAGRANT_CWD")