Get plugins from basis

This commit is contained in:
sophia 2021-11-30 16:22:51 -06:00 committed by Paul Hinze
parent 9651e1a756
commit f1dc606d11
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -162,6 +162,37 @@ func (b *Basis) DataDir() (*datadir.Basis, error) {
return b.dir, nil
}
var StringComponentTypeMap = map[string]component.Type{
"command": component.CommandType,
"communicator": component.CommunicatorType,
"guest": component.GuestType,
"host": component.HostType,
"provider": component.ProviderType,
"provisioner": component.ProvisionerType,
"synced_folder": component.SyncedFolderType,
}
// Implements core.Basis
// Returns all the registered plugins of the types specified
func (b *Basis) Plugins(types ...string) (plugins []*core.NamedPlugin, err error) {
plugins = []*core.NamedPlugin{}
for _, pluginType := range types {
typ := StringComponentTypeMap[pluginType]
components, err := b.typeComponents(b.ctx, typ)
if err != nil {
return nil, err
}
for name, h := range components {
plugins = append(plugins, &core.NamedPlugin{
Plugin: h.Value,
Name: name,
Type: pluginType,
})
}
}
return
}
// Generic function for providing ref to a scope
func (b *Basis) Ref() interface{} {
return &vagrant_plugin_sdk.Ref_Basis{