Peter
5af8ddceab
Some checks failed
continuous-integration/drone/push Build is failing
- introduce individual commands to manage plugins - store plugin in state to skip loading them to memory every time
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"code.icb4dc0.de/buildr/buildr/internal/config"
|
|
"code.icb4dc0.de/buildr/buildr/internal/plugins"
|
|
"code.icb4dc0.de/buildr/buildr/internal/services"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
)
|
|
|
|
var _ PluginCommander = (*PluginApp)(nil)
|
|
|
|
type PluginAppServiceAccess interface {
|
|
services.PluginsRepoAccessor
|
|
}
|
|
|
|
func NewPluginApp(buildrCfg *config.Buildr, pluginMgr *plugins.Manager, svcAcc PluginAppServiceAccess) *PluginApp {
|
|
return &PluginApp{
|
|
buildrCfg: buildrCfg,
|
|
pluginMgr: pluginMgr,
|
|
svcAcc: svcAcc,
|
|
}
|
|
}
|
|
|
|
type PluginApp struct {
|
|
buildrCfg *config.Buildr
|
|
pluginMgr *plugins.Manager
|
|
svcAcc PluginAppServiceAccess
|
|
}
|
|
|
|
func (p PluginApp) ListPlugins(ctx context.Context, writer io.Writer) error {
|
|
knownPlugins, err := p.svcAcc.PluginsRepo().List(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
table := tablewriter.NewWriter(writer)
|
|
table.SetHeader([]string{"Name"})
|
|
for _, plugin := range knownPlugins {
|
|
table.Append([]string{plugin.Name})
|
|
}
|
|
|
|
table.Render()
|
|
return nil
|
|
}
|
|
|
|
func (p PluginApp) UpdatePlugins(ctx context.Context) error {
|
|
return p.pluginMgr.UpdatePlugins(ctx, p.buildrCfg.Plugins...)
|
|
}
|