Skip to content

Commit

Permalink
Refactor according to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk committed Sep 21, 2023
1 parent 1dadced commit c8d0a42
Show file tree
Hide file tree
Showing 120 changed files with 3,862 additions and 1,538 deletions.
44 changes: 23 additions & 21 deletions cmd/kn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/spf13/cobra"
"knative.dev/client/pkg/kn/config"
"knative.dev/client/pkg/kn/plugin"
pluginpkg "knative.dev/client/pkg/kn/plugin"
"knative.dev/client/pkg/kn/root"
)

Expand Down Expand Up @@ -60,7 +60,7 @@ func run(args []string) error {
return err
}

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

// Create kn root command and all sub-commands
rootCmd, err := root.NewRootCommand(pluginManager.HelpTemplateFuncs())
Expand All @@ -78,31 +78,33 @@ func run(args []string) error {
// reset the temporary setting
rootCmd.FParseErrWhitelist = cobra.FParseErrWhitelist{UnknownFlags: false} // wokeignore:rule=whitelist // TODO(#1031)

ctxManager, err := plugin.NewContextManager()
if err != nil {
return err
}
//defer func(ctxManager *plugin.ContextDataManager) {
// err := ctxManager.WriteCache()
// if err != nil {
// println("error during write")
// }
//}(ctxManager)

// Find plugin with the commands arguments
plugin, err := pluginManager.FindPlugin(commands)
if err != nil {
return err
}

// FT: Context Sharing
err = ctxManager.FetchManifests(pluginManager)
if err != nil {
return err
}
//TODO: remove once implemented
if err := ctxManager.WriteCache(); err != nil {
return err
if config.GlobalConfig.ContextSharing() {
ctxManager, err := pluginpkg.NewContextManager()
if err != nil {
return err
}

defer func(ctxManager *pluginpkg.ContextDataManager) {
if err := ctxManager.WriteCache(); err != nil {
println("error during write")
}
}(ctxManager)

err = ctxManager.FetchManifests(pluginManager)
if err != nil {
return err
}

// Inject shared context data as context.Context
contextData := ctxManager.FetchContextData(pluginManager)
rootCmd.SetContext(contextData)
}

if plugin != nil {
Expand Down Expand Up @@ -161,7 +163,7 @@ func filterHelpOptions(args []string) []string {
}

// Check if the plugin collides with any command specified in the root command
func validatePlugin(root *cobra.Command, plugin plugin.Plugin) error {
func validatePlugin(root *cobra.Command, plugin pluginpkg.Plugin) error {
// Check if a given plugin can be identified as a command
cmd, args, err := root.Find(plugin.CommandParts())

Expand Down
6 changes: 3 additions & 3 deletions cmd/kn/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func TestRun(t *testing.T) {
args []string
expectedOut []string
expectedErrOut []string
plugin plugin.Plugin
plugin pluginpkg.Plugin

Check failure on line 364 in cmd/kn/main_test.go

View workflow job for this annotation

GitHub Actions / build / Build

undefined: pluginpkg

Check failure on line 364 in cmd/kn/main_test.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

undefined: pluginpkg
}{
{
[]string{"kn", "version"},
Expand Down Expand Up @@ -425,8 +425,8 @@ func TestRun(t *testing.T) {
for _, tc := range testCases {
os.Args = tc.args
if tc.plugin != nil {
plugin.InternalPlugins = plugin.PluginList{}
plugin.InternalPlugins = append(plugin.InternalPlugins, tc.plugin)
pluginpkg.InternalPlugins = pluginpkg.PluginList{}

Check failure on line 428 in cmd/kn/main_test.go

View workflow job for this annotation

GitHub Actions / build / Build

undefined: pluginpkg

Check failure on line 428 in cmd/kn/main_test.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

undefined: pluginpkg
pluginpkg.InternalPlugins = append(pluginpkg.InternalPlugins, tc.plugin)

Check failure on line 429 in cmd/kn/main_test.go

View workflow job for this annotation

GitHub Actions / build / Build

undefined: pluginpkg

Check failure on line 429 in cmd/kn/main_test.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

undefined: pluginpkg
}
capture := test.CaptureOutput(t)
err := run(tc.args[1:])
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/spf13/viper v1.16.0
golang.org/x/mod v0.12.0
golang.org/x/term v0.12.0
gotest.tools/v3 v3.3.0
gotest.tools/v3 v3.4.0
k8s.io/api v0.26.5
k8s.io/apiextensions-apiserver v0.26.5
k8s.io/apimachinery v0.26.5
Expand All @@ -29,7 +29,7 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2
require k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5

require (
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
Expand All @@ -51,21 +51,21 @@ require (
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-containerregistry v0.13.0 // indirect
github.com/google/go-containerregistry v0.15.2 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -88,8 +88,8 @@ require (
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/statsd_exporter v0.22.8 // indirect
github.com/rickb777/date v1.20.0 // indirect
github.com/prometheus/statsd_exporter v0.23.0 // indirect
github.com/rickb777/date v1.20.1 // indirect
github.com/rickb777/plural v1.4.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down Expand Up @@ -123,9 +123,9 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9 // indirect
k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
Loading

0 comments on commit c8d0a42

Please sign in to comment.