Use factory values only if provided options left unset

This commit is contained in:
Chris Roberts 2022-07-07 10:59:28 -07:00
parent a3b32bdf60
commit 5619341880

View File

@ -70,11 +70,7 @@ func (f *Factory) NewBasis(resourceId string, opts ...BasisOption) (*Basis, erro
}
opts = append(opts,
WithClient(f.client),
WithFactory(f),
WithLogger(f.logger),
WithUI(f.ui),
WithPluginManager(f.plugins),
)
b, err := NewBasis(f.ctx, opts...)
@ -82,6 +78,20 @@ func (f *Factory) NewBasis(resourceId string, opts ...BasisOption) (*Basis, erro
return nil, err
}
// Set any unset values which we can provide
if b.client == nil {
b.client = f.client
}
if b.logger == nil {
b.logger = f.logger
}
if b.ui == nil {
b.ui = f.ui
}
if b.plugins == nil {
b.plugins = f.plugins
}
// Now that we have the basis information loaded, check if
// we have a cached version and return that if so
if existingB, ok := f.cache.Fetch(b.basis.ResourceId); ok {