From f1dc606d11290380fa4c6bef8855fca8287fc484 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 30 Nov 2021 16:22:51 -0600 Subject: [PATCH] Get plugins from basis --- internal/core/basis.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/internal/core/basis.go b/internal/core/basis.go index e4622e9d4..a009c1d03 100644 --- a/internal/core/basis.go +++ b/internal/core/basis.go @@ -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{