Add mappers to component at component creation phase

This commit is contained in:
sophia 2021-10-27 10:34:07 -05:00 committed by Paul Hinze
parent 63c71b0a20
commit c4cd5c599b
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 9 additions and 9 deletions

View File

@ -552,10 +552,6 @@ type HasParents interface {
Parent() (string, error)
}
type HasMappers interface {
AppendMappers(...*argmapper.Func)
}
func (b *Basis) loadParentPlugin(p *plugin.Plugin, typ component.Type) (err error) {
plg, err := p.InstanceOf(typ)
if err != nil {
@ -630,11 +626,7 @@ func (b *Basis) component(
// TODO(spox): we need to add hooks
if cm, ok := c.Component.(HasMappers); ok {
cm.AppendMappers(c.Mappers...)
}
hooks := map[string][]*config.Hook{}
allMappers := append(b.mappers, p.Mappers...)
return &Component{
Value: c.Component,
Info: &vagrant_server.Component{
@ -643,7 +635,7 @@ func (b *Basis) component(
ServerAddr: b.Client().ServerTarget(),
},
hooks: hooks,
mappers: allMappers,
mappers: append(b.mappers, p.Mappers...),
plugin: c,
}, nil
}

View File

@ -176,6 +176,10 @@ func (p *Plugin) InstanceOf(
c.SetCache(p.Cache)
}
if cm, ok := raw.(HasMappers); ok {
cm.AppendMappers(p.Mappers...)
}
i = &Instance{
Component: raw,
Broker: b.GRPCBroker(),
@ -188,6 +192,10 @@ func (p *Plugin) InstanceOf(
return
}
type HasMappers interface {
AppendMappers(...*argmapper.Func)
}
func (p *Plugin) SeedPlugin(typ component.Type, args ...interface{}) error {
seedTarget := p.components[typ].Component
if s, ok := seedTarget.(core.Seeder); ok {