Skip to content

Commit

Permalink
Move list merge into plugin manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk committed Jul 13, 2023
1 parent c22cfd5 commit bfaf3f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 0 additions & 7 deletions cmd/kn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"knative.dev/client/pkg/kn/config"
"knative.dev/client/pkg/kn/plugin"
"knative.dev/client/pkg/kn/root"

pkgplugin "knative.dev/client-pkg/pkg/kn/plugin"
)

func main() {
Expand Down Expand Up @@ -64,11 +62,6 @@ func run(args []string) error {

pluginManager := plugin.NewManager(config.GlobalConfig.PluginsDir(), config.GlobalConfig.LookupPluginsInPath())

// Merge plugins that implements client-pkg Plugin type to the same manager instance
for _, p := range pkgplugin.InternalPlugins {
pluginManager.AppendPlugin(p)
}

// Create kn root command and all sub-commands
rootCmd, err := root.NewRootCommand(pluginManager.HelpTemplateFuncs())
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion pkg/kn/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package plugin
import (
"errors"
"fmt"
pkgplugin "knative.dev/client-pkg/pkg/kn/plugin"
"os"
"os/exec"
"path/filepath"
Expand All @@ -32,6 +33,8 @@ import (
// Allow plugins to register to this slice for inlining
var InternalPlugins PluginList

var synced bool

// Interface describing a plugin
type Plugin interface {
// Get the name of the plugin (the file name without extensions)
Expand Down Expand Up @@ -104,10 +107,17 @@ func (p PluginList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

// NewManager creates a new manager for looking up plugins on the file system
func NewManager(pluginDir string, lookupInPath bool) *Manager {
return &Manager{
m := &Manager{
pluginsDir: pluginDir,
lookupInPath: lookupInPath,
}
if !synced {
for _, p := range pkgplugin.InternalPlugins {
m.AppendPlugin(p)
}
synced = true
}
return m
}

func (manager *Manager) AppendPlugin(plugin Plugin) {
Expand Down

0 comments on commit bfaf3f9

Please sign in to comment.