From 9d24ffae22cc0516676e67a5b004c30a5840b4e0 Mon Sep 17 00:00:00 2001 From: Chris Suszynski Date: Wed, 20 Mar 2024 12:56:00 +0100 Subject: [PATCH] Clean up the kn sub-package (#155) --- pkg/{kn => }/commands/describe.go | 0 pkg/{kn => }/commands/describe_test.go | 0 pkg/{kn => }/commands/flags/listprint.go | 2 +- pkg/{kn => }/commands/flags/listprint_test.go | 0 pkg/{kn => }/commands/flags/sink.go | 2 +- pkg/{kn => }/commands/flags/sink_test.go | 0 pkg/{kn => }/commands/human_readable_flags.go | 0 .../commands/human_readable_flags_test.go | 0 pkg/{kn => }/commands/namespaced.go | 0 pkg/{kn => }/commands/namespaced_test.go | 0 pkg/{kn => }/commands/testing_helper.go | 2 +- pkg/{kn => }/commands/types.go | 0 pkg/{kn => }/commands/types_test.go | 0 pkg/{kn => }/config/config.go | 30 ++++++++++--------- pkg/{kn => }/config/config_test.go | 30 ++++++++++--------- pkg/{kn => }/config/types.go | 0 pkg/{kn => }/flags/bool.go | 0 pkg/{kn => }/flags/bool_test.go | 0 pkg/{kn => }/flags/podspec_helper.go | 0 pkg/{kn => }/flags/podspec_helper_test.go | 0 .../pkg/factories/flags_factory.go | 5 ++-- .../pkg/factories/kn_source_factory.go | 3 +- .../pkg/factories/kn_source_factory_test.go | 3 +- pkg/kn-source-pkg/pkg/types/structs.go | 4 +-- pkg/kn-source-pkg/pkg/types/structs_test.go | 3 +- pkg/kn/plugin/types.go | 30 ------------------- pkg/serving/config_changes.go | 2 +- 27 files changed, 43 insertions(+), 73 deletions(-) rename pkg/{kn => }/commands/describe.go (100%) rename pkg/{kn => }/commands/describe_test.go (100%) rename pkg/{kn => }/commands/flags/listprint.go (98%) rename pkg/{kn => }/commands/flags/listprint_test.go (100%) rename pkg/{kn => }/commands/flags/sink.go (99%) rename pkg/{kn => }/commands/flags/sink_test.go (100%) rename pkg/{kn => }/commands/human_readable_flags.go (100%) rename pkg/{kn => }/commands/human_readable_flags_test.go (100%) rename pkg/{kn => }/commands/namespaced.go (100%) rename pkg/{kn => }/commands/namespaced_test.go (100%) rename pkg/{kn => }/commands/testing_helper.go (98%) rename pkg/{kn => }/commands/types.go (100%) rename pkg/{kn => }/commands/types_test.go (100%) rename pkg/{kn => }/config/config.go (92%) rename pkg/{kn => }/config/config_test.go (83%) rename pkg/{kn => }/config/types.go (100%) rename pkg/{kn => }/flags/bool.go (100%) rename pkg/{kn => }/flags/bool_test.go (100%) rename pkg/{kn => }/flags/podspec_helper.go (100%) rename pkg/{kn => }/flags/podspec_helper_test.go (100%) delete mode 100644 pkg/kn/plugin/types.go diff --git a/pkg/kn/commands/describe.go b/pkg/commands/describe.go similarity index 100% rename from pkg/kn/commands/describe.go rename to pkg/commands/describe.go diff --git a/pkg/kn/commands/describe_test.go b/pkg/commands/describe_test.go similarity index 100% rename from pkg/kn/commands/describe_test.go rename to pkg/commands/describe_test.go diff --git a/pkg/kn/commands/flags/listprint.go b/pkg/commands/flags/listprint.go similarity index 98% rename from pkg/kn/commands/flags/listprint.go rename to pkg/commands/flags/listprint.go index ed562c9e..098674f9 100644 --- a/pkg/kn/commands/flags/listprint.go +++ b/pkg/commands/flags/listprint.go @@ -20,8 +20,8 @@ import ( "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" + "knative.dev/client-pkg/pkg/commands" - "knative.dev/client-pkg/pkg/kn/commands" hprinters "knative.dev/client-pkg/pkg/printers" "knative.dev/client-pkg/pkg/util" ) diff --git a/pkg/kn/commands/flags/listprint_test.go b/pkg/commands/flags/listprint_test.go similarity index 100% rename from pkg/kn/commands/flags/listprint_test.go rename to pkg/commands/flags/listprint_test.go diff --git a/pkg/kn/commands/flags/sink.go b/pkg/commands/flags/sink.go similarity index 99% rename from pkg/kn/commands/flags/sink.go rename to pkg/commands/flags/sink.go index 509b8245..5a1c0281 100644 --- a/pkg/kn/commands/flags/sink.go +++ b/pkg/commands/flags/sink.go @@ -22,11 +22,11 @@ import ( "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/client-pkg/pkg/config" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" clientdynamic "knative.dev/client-pkg/pkg/dynamic" - "knative.dev/client-pkg/pkg/kn/config" ) type SinkFlags struct { diff --git a/pkg/kn/commands/flags/sink_test.go b/pkg/commands/flags/sink_test.go similarity index 100% rename from pkg/kn/commands/flags/sink_test.go rename to pkg/commands/flags/sink_test.go diff --git a/pkg/kn/commands/human_readable_flags.go b/pkg/commands/human_readable_flags.go similarity index 100% rename from pkg/kn/commands/human_readable_flags.go rename to pkg/commands/human_readable_flags.go diff --git a/pkg/kn/commands/human_readable_flags_test.go b/pkg/commands/human_readable_flags_test.go similarity index 100% rename from pkg/kn/commands/human_readable_flags_test.go rename to pkg/commands/human_readable_flags_test.go diff --git a/pkg/kn/commands/namespaced.go b/pkg/commands/namespaced.go similarity index 100% rename from pkg/kn/commands/namespaced.go rename to pkg/commands/namespaced.go diff --git a/pkg/kn/commands/namespaced_test.go b/pkg/commands/namespaced_test.go similarity index 100% rename from pkg/kn/commands/namespaced_test.go rename to pkg/commands/namespaced_test.go diff --git a/pkg/kn/commands/testing_helper.go b/pkg/commands/testing_helper.go similarity index 98% rename from pkg/kn/commands/testing_helper.go rename to pkg/commands/testing_helper.go index 2f23da9b..8582febd 100644 --- a/pkg/kn/commands/testing_helper.go +++ b/pkg/commands/testing_helper.go @@ -18,13 +18,13 @@ import ( "bytes" "knative.dev/client-pkg/pkg/dynamic/fake" + "knative.dev/client-pkg/pkg/flags" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/runtime" clienttesting "k8s.io/client-go/testing" servingv1fake "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1/fake" - "knative.dev/client-pkg/pkg/kn/flags" clientservingv1 "knative.dev/client-pkg/pkg/serving/v1" v1 "knative.dev/client-pkg/pkg/sources/v1" diff --git a/pkg/kn/commands/types.go b/pkg/commands/types.go similarity index 100% rename from pkg/kn/commands/types.go rename to pkg/commands/types.go diff --git a/pkg/kn/commands/types_test.go b/pkg/commands/types_test.go similarity index 100% rename from pkg/kn/commands/types_test.go rename to pkg/commands/types_test.go diff --git a/pkg/kn/config/config.go b/pkg/config/config.go similarity index 92% rename from pkg/kn/config/config.go rename to pkg/config/config.go index e1b6340c..8f548bfe 100644 --- a/pkg/kn/config/config.go +++ b/pkg/config/config.go @@ -1,16 +1,18 @@ -// Copyright © 2020 The Knative Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + Copyright 2024 The Knative Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ package config @@ -21,7 +23,7 @@ import ( "path/filepath" "runtime" - homedir "github.com/mitchellh/go-homedir" + "github.com/mitchellh/go-homedir" flag "github.com/spf13/pflag" "github.com/spf13/viper" ) diff --git a/pkg/kn/config/config_test.go b/pkg/config/config_test.go similarity index 83% rename from pkg/kn/config/config_test.go rename to pkg/config/config_test.go index a21a1dcd..af206e65 100644 --- a/pkg/kn/config/config_test.go +++ b/pkg/config/config_test.go @@ -1,16 +1,18 @@ -// Copyright © 2020 The Knative Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + Copyright 2024 The Knative Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ package config @@ -19,7 +21,7 @@ import ( "path/filepath" "testing" - homedir "github.com/mitchellh/go-homedir" + "github.com/mitchellh/go-homedir" "github.com/spf13/viper" "gotest.tools/v3/assert" ) diff --git a/pkg/kn/config/types.go b/pkg/config/types.go similarity index 100% rename from pkg/kn/config/types.go rename to pkg/config/types.go diff --git a/pkg/kn/flags/bool.go b/pkg/flags/bool.go similarity index 100% rename from pkg/kn/flags/bool.go rename to pkg/flags/bool.go diff --git a/pkg/kn/flags/bool_test.go b/pkg/flags/bool_test.go similarity index 100% rename from pkg/kn/flags/bool_test.go rename to pkg/flags/bool_test.go diff --git a/pkg/kn/flags/podspec_helper.go b/pkg/flags/podspec_helper.go similarity index 100% rename from pkg/kn/flags/podspec_helper.go rename to pkg/flags/podspec_helper.go diff --git a/pkg/kn/flags/podspec_helper_test.go b/pkg/flags/podspec_helper_test.go similarity index 100% rename from pkg/kn/flags/podspec_helper_test.go rename to pkg/flags/podspec_helper_test.go diff --git a/pkg/kn-source-pkg/pkg/factories/flags_factory.go b/pkg/kn-source-pkg/pkg/factories/flags_factory.go index ea778323..62ba3674 100644 --- a/pkg/kn-source-pkg/pkg/factories/flags_factory.go +++ b/pkg/kn-source-pkg/pkg/factories/flags_factory.go @@ -15,10 +15,9 @@ package factories import ( - "knative.dev/client-pkg/pkg/kn-source-pkg/pkg/types" - "knative.dev/client-pkg/pkg/kn/commands" - "github.com/spf13/pflag" + "knative.dev/client-pkg/pkg/commands" + "knative.dev/client-pkg/pkg/kn-source-pkg/pkg/types" ) type DefautFlagsFactory struct { diff --git a/pkg/kn-source-pkg/pkg/factories/kn_source_factory.go b/pkg/kn-source-pkg/pkg/factories/kn_source_factory.go index 0ba8c7c5..a8e11e56 100644 --- a/pkg/kn-source-pkg/pkg/factories/kn_source_factory.go +++ b/pkg/kn-source-pkg/pkg/factories/kn_source_factory.go @@ -16,10 +16,9 @@ package factories import ( "k8s.io/client-go/rest" + "knative.dev/client-pkg/pkg/commands/flags" "knative.dev/client-pkg/pkg/kn-source-pkg/pkg/client" "knative.dev/client-pkg/pkg/kn-source-pkg/pkg/types" - - "knative.dev/client-pkg/pkg/kn/commands/flags" ) type DefautKnSourceFactory struct { diff --git a/pkg/kn-source-pkg/pkg/factories/kn_source_factory_test.go b/pkg/kn-source-pkg/pkg/factories/kn_source_factory_test.go index 538e5384..aa3053a9 100644 --- a/pkg/kn-source-pkg/pkg/factories/kn_source_factory_test.go +++ b/pkg/kn-source-pkg/pkg/factories/kn_source_factory_test.go @@ -19,9 +19,8 @@ import ( "gotest.tools/v3/assert" "k8s.io/client-go/rest" + "knative.dev/client-pkg/pkg/commands/flags" "knative.dev/client-pkg/pkg/kn-source-pkg/pkg/types" - "knative.dev/client-pkg/pkg/kn/commands/flags" - "knative.dev/client-pkg/pkg/kn-source-pkg/pkg/types/typesfakes" ) diff --git a/pkg/kn-source-pkg/pkg/types/structs.go b/pkg/kn-source-pkg/pkg/types/structs.go index 9d5236cc..82ad787f 100644 --- a/pkg/kn-source-pkg/pkg/types/structs.go +++ b/pkg/kn-source-pkg/pkg/types/structs.go @@ -18,8 +18,8 @@ package types import ( "github.com/spf13/cobra" - "knative.dev/client-pkg/pkg/kn/commands" - "knative.dev/client-pkg/pkg/kn/commands/flags" + "knative.dev/client-pkg/pkg/commands" + "knative.dev/client-pkg/pkg/commands/flags" ) type KnSourceParams struct { diff --git a/pkg/kn-source-pkg/pkg/types/structs_test.go b/pkg/kn-source-pkg/pkg/types/structs_test.go index 385e2f4a..78bf1e2b 100644 --- a/pkg/kn-source-pkg/pkg/types/structs_test.go +++ b/pkg/kn-source-pkg/pkg/types/structs_test.go @@ -19,8 +19,7 @@ import ( "github.com/spf13/cobra" "gotest.tools/v3/assert" - - "knative.dev/client-pkg/pkg/kn/commands/flags" + "knative.dev/client-pkg/pkg/commands/flags" ) func TestAddCommonFlags(t *testing.T) { diff --git a/pkg/kn/plugin/types.go b/pkg/kn/plugin/types.go deleted file mode 100644 index 1d740b9a..00000000 --- a/pkg/kn/plugin/types.go +++ /dev/null @@ -1,30 +0,0 @@ -package plugin - -// Allow plugins to register to this slice for inlining -var InternalPlugins PluginList - -// Interface describing a plugin -type Plugin interface { - // Get the name of the plugin (the file name without extensions) - Name() string - - // Execute the plugin with the given arguments - Execute(args []string) error - - // Return a description of the plugin (if support by the plugin binary) - Description() (string, error) - - // The command path leading to this plugin. - // Eg. for a plugin "kn source github" this will be [ "source", "github" ] - CommandParts() []string - - // Location of the plugin where it is stored in the filesystem - Path() string -} - -// Used for sorting a list of plugins -type PluginList []Plugin - -func (p PluginList) Len() int { return len(p) } -func (p PluginList) Less(i, j int) bool { return p[i].Name() < p[j].Name() } -func (p PluginList) Swap(i, j int) { p[i], p[j] = p[j], p[i] } diff --git a/pkg/serving/config_changes.go b/pkg/serving/config_changes.go index 4a7f1532..f16d478f 100644 --- a/pkg/serving/config_changes.go +++ b/pkg/serving/config_changes.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "knative.dev/client-pkg/pkg/kn/flags" + "knative.dev/client-pkg/pkg/flags" "knative.dev/pkg/ptr" "knative.dev/serving/pkg/apis/autoscaling" servingconfig "knative.dev/serving/pkg/apis/config"