Remove lookup-plugins flag (#1506)

Co-authored-by: Roland Huß <roland@ro14nd.de>
This commit is contained in:
Gunjan Vyas 2021-11-02 22:56:41 +05:30 committed by GitHub
parent c1e35893f7
commit da6f164dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 37 deletions

View File

@ -203,11 +203,6 @@ func TestStripFlags(t *testing.T) {
[]string{"test", "second"}, []string{"test", "second"},
"", "",
}, },
{
[]string{"--lookup-plugins", "bla", "test", "second"},
[]string{"bla", "test", "second"},
"",
},
{ {
[]string{"--config-file", "bla", "test", "second"}, []string{"--config-file", "bla", "test", "second"},
[]string{"test", "second"}, []string{"test", "second"},

View File

@ -88,13 +88,7 @@ func (c *config) PluginsDir() string {
// LookupPluginsInPath returns true if plugins should be also checked in the pat // LookupPluginsInPath returns true if plugins should be also checked in the pat
func (c *config) LookupPluginsInPath() bool { func (c *config) LookupPluginsInPath() bool {
if viper.IsSet(deprecatedKeyPluginsLookupInPath) { return bootstrapDefaults.lookupPluginsInPath
return viper.GetBool(deprecatedKeyPluginsLookupInPath)
} else {
// If legacy branch is removed, switch to setting the default to viper
// See TODO comment below.
return bootstrapDefaults.lookupPluginsInPath
}
} }
func (c *config) SinkMappings() []SinkMapping { func (c *config) SinkMappings() []SinkMapping {
@ -131,10 +125,6 @@ func BootstrapConfig() error {
if err != nil { if err != nil {
return err return err
} }
err = viper.BindPFlag(deprecatedKeyPluginsLookupInPath, bootstrapFlagSet.Lookup(flagPluginsLookupInPath))
if err != nil {
return err
}
viper.SetConfigFile(GlobalConfig.ConfigFile()) viper.SetConfigFile(GlobalConfig.ConfigFile())
configFile := GlobalConfig.ConfigFile() configFile := GlobalConfig.ConfigFile()
@ -159,7 +149,6 @@ func BootstrapConfig() error {
// TODO: Re-enable when legacy handling for plugin config has been removed // TODO: Re-enable when legacy handling for plugin config has been removed
// For now default handling is happening directly in the getter of GlobalConfig // For now default handling is happening directly in the getter of GlobalConfig
// viper.SetDefault(keyPluginsDirectory, bootstrapDefaults.pluginsDir) // viper.SetDefault(keyPluginsDirectory, bootstrapDefaults.pluginsDir)
// viper.SetDefault(deprecatedKeyPluginsLookupInPath, bootstrapDefaults.lookupPluginsInPath)
// If a config file is found, read it in. // If a config file is found, read it in.
err = viper.ReadInConfig() err = viper.ReadInConfig()
@ -182,10 +171,8 @@ func BootstrapConfig() error {
func AddBootstrapFlags(flags *flag.FlagSet) { func AddBootstrapFlags(flags *flag.FlagSet) {
flags.StringVar(&globalConfig.configFile, "config", "", fmt.Sprintf("kn configuration file (default: %s)", defaultConfigFileForUsageMessage())) flags.StringVar(&globalConfig.configFile, "config", "", fmt.Sprintf("kn configuration file (default: %s)", defaultConfigFileForUsageMessage()))
flags.String(flagPluginsDir, "", "Directory holding kn plugins") flags.String(flagPluginsDir, "", "Directory holding kn plugins")
flags.Bool(flagPluginsLookupInPath, false, "Search kn plugins also in $PATH")
// Let's try that and mark the flags as hidden: (as those configuration is a permanent choice of operation) // Let's try that and mark the flags as hidden: (as those configuration is a permanent choice of operation)
flags.MarkHidden(flagPluginsLookupInPath)
flags.MarkHidden(flagPluginsDir) flags.MarkHidden(flagPluginsDir)
} }

View File

@ -70,10 +70,9 @@ type ChannelTypeMapping struct {
// config Keys for looking up in viper // config Keys for looking up in viper
const ( const (
keyPluginsDirectory = "plugins.directory" keyPluginsDirectory = "plugins.directory"
deprecatedKeyPluginsLookupInPath = "plugins.path-lookup" keySinkMappings = "eventing.sink-mappings"
keySinkMappings = "eventing.sink-mappings" keyChannelTypeMappings = "eventing.channel-type-mappings"
keyChannelTypeMappings = "eventing.channel-type-mappings"
) )
// legacy config keys, deprecated // legacy config keys, deprecated
@ -85,6 +84,5 @@ const (
// Global (hidden) flags // Global (hidden) flags
// TODO: Remove me if decided that they are not needed // TODO: Remove me if decided that they are not needed
const ( const (
flagPluginsDir = "plugins-dir" flagPluginsDir = "plugins-dir"
flagPluginsLookupInPath = "lookup-plugins"
) )

View File

@ -122,16 +122,13 @@ func TestPluginWithoutLookup(t *testing.T) {
r := test.NewKnRunResultCollector(t, it) r := test.NewKnRunResultCollector(t, it)
defer r.DumpIfFailed() defer r.DumpIfFailed()
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=false"} knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)}
t.Log("list plugin in --plugins-dir") t.Log("list plugin in --plugins-dir")
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{}) listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{})
t.Log("execute plugin in --plugins-dir") t.Log("execute plugin in --plugins-dir")
runPlugin(r, knFlags, "helloe2e", []string{"e2e", "test"}, []string{"Hello Knative, I'm a Kn plugin", "I received arguments", "e2e"}) runPlugin(r, knFlags, "helloe2e", []string{"e2e", "test"}, []string{"Hello Knative, I'm a Kn plugin", "I received arguments", "e2e"})
t.Log("does not list any other plugin in $PATH")
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
} }
func TestPluginInHelpMessage(t *testing.T) { func TestPluginInHelpMessage(t *testing.T) {
@ -159,7 +156,7 @@ func TestPluginWithLookup(t *testing.T) {
assert.NilError(t, pc.setup()) assert.NilError(t, pc.setup())
defer pc.teardown() defer pc.teardown()
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"} knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)}
t.Log("list plugin in --plugins-dir") t.Log("list plugin in --plugins-dir")
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2}) listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
@ -178,7 +175,7 @@ func TestListPluginInPath(t *testing.T) {
defer tearDownWithPath(pc, oldPath) defer tearDownWithPath(pc, oldPath)
t.Log("list plugin in $PATH") t.Log("list plugin in $PATH")
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"} knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)}
listPlugin(r, knFlags, []string{pc.knPluginPath, pc.knPluginPath2}, []string{}) listPlugin(r, knFlags, []string{pc.knPluginPath, pc.knPluginPath2}, []string{})
r.DumpIfFailed() r.DumpIfFailed()
@ -195,7 +192,7 @@ func TestExecutePluginInPath(t *testing.T) {
defer tearDownWithPath(pc, oldPath) defer tearDownWithPath(pc, oldPath)
t.Log("execute plugin in $PATH") t.Log("execute plugin in $PATH")
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"} knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)}
runPlugin(r, knFlags, "hello2e2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"}) runPlugin(r, knFlags, "hello2e2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"})
} }
@ -218,11 +215,6 @@ func TestExecutePluginInPathWithError(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
assert.NilError(t, os.Setenv("PATH", fmt.Sprintf("%s%s%s", oldPath, delim, pluginsDir))) assert.NilError(t, os.Setenv("PATH", fmt.Sprintf("%s%s%s", oldPath, delim, pluginsDir)))
defer tearDownWithPath(pc, oldPath) defer tearDownWithPath(pc, oldPath)
out := test.Kn{}.Run("--lookup-plugins=true", "hello3e2e")
r.AssertError(out)
assert.Check(r.T(), util.ContainsAll(out.Stderr, "Error: exit status 1"))
assert.Check(r.T(), util.ContainsNone(out.Stderr, "Run", "kn --help", "usage"))
} }
// Private // Private