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 bcf822c commit 63dded1
Show file tree
Hide file tree
Showing 150 changed files with 4,367 additions and 1,799 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
}{
{
[]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{}
pluginpkg.InternalPlugins = append(pluginpkg.InternalPlugins, tc.plugin)
}
capture := test.CaptureOutput(t)
err := run(tc.args[1:])
Expand Down
50 changes: 25 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ require (
github.com/spf13/viper v1.16.0
golang.org/x/mod v0.12.0
golang.org/x/term v0.11.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
k8s.io/cli-runtime v0.26.5
k8s.io/client-go v0.26.5
k8s.io/code-generator v0.26.5
knative.dev/client-pkg v0.0.0-20230815131440-5abd12981b4b
knative.dev/eventing v0.38.1-0.20230822134255-a2e2aa3d515d
knative.dev/client-pkg v0.0.0-20230914131734-b21a925efce6
knative.dev/eventing v0.38.1-0.20230831151434-10e25b91d471
knative.dev/hack v0.0.0-20230818155117-9cc05a31e8c0
knative.dev/networking v0.0.0-20230822003854-1d7920d27b9e
knative.dev/pkg v0.0.0-20230821102121-81e4ee140363
knative.dev/serving v0.38.1-0.20230823024257-eaff0b39b99e
knative.dev/networking v0.0.0-20230830115731-dfd6edf47b91
knative.dev/pkg v0.0.0-20230829134737-fcccb4e1a0a4
knative.dev/serving v0.38.1-0.20230831173934-8dbb2d35192a
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 @@ -40,32 +40,32 @@ require (
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudevents/sdk-go/sql/v2 v2.13.0 // indirect
github.com/cloudevents/sdk-go/v2 v2.13.0 // indirect
github.com/cloudevents/sdk-go/v2 v2.14.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
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.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // 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.0 // 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 @@ -80,16 +80,16 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
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 All @@ -110,7 +110,7 @@ require (
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/api v0.138.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
Expand All @@ -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 63dded1

Please sign in to comment.