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{"--lookup-plugins", "bla", "test", "second"},
[]string{"bla", "test", "second"},
"",
},
{
[]string{"--config-file", "bla", "test", "second"},
[]string{"test", "second"},

View File

@ -88,14 +88,8 @@ func (c *config) PluginsDir() string {
// LookupPluginsInPath returns true if plugins should be also checked in the pat
func (c *config) LookupPluginsInPath() bool {
if viper.IsSet(deprecatedKeyPluginsLookupInPath) {
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 {
return c.sinkMappings
@ -131,10 +125,6 @@ func BootstrapConfig() error {
if err != nil {
return err
}
err = viper.BindPFlag(deprecatedKeyPluginsLookupInPath, bootstrapFlagSet.Lookup(flagPluginsLookupInPath))
if err != nil {
return err
}
viper.SetConfigFile(GlobalConfig.ConfigFile())
configFile := GlobalConfig.ConfigFile()
@ -159,7 +149,6 @@ func BootstrapConfig() error {
// TODO: Re-enable when legacy handling for plugin config has been removed
// For now default handling is happening directly in the getter of GlobalConfig
// viper.SetDefault(keyPluginsDirectory, bootstrapDefaults.pluginsDir)
// viper.SetDefault(deprecatedKeyPluginsLookupInPath, bootstrapDefaults.lookupPluginsInPath)
// If a config file is found, read it in.
err = viper.ReadInConfig()
@ -182,10 +171,8 @@ func BootstrapConfig() error {
func AddBootstrapFlags(flags *flag.FlagSet) {
flags.StringVar(&globalConfig.configFile, "config", "", fmt.Sprintf("kn configuration file (default: %s)", defaultConfigFileForUsageMessage()))
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)
flags.MarkHidden(flagPluginsLookupInPath)
flags.MarkHidden(flagPluginsDir)
}

View File

@ -71,7 +71,6 @@ type ChannelTypeMapping struct {
// config Keys for looking up in viper
const (
keyPluginsDirectory = "plugins.directory"
deprecatedKeyPluginsLookupInPath = "plugins.path-lookup"
keySinkMappings = "eventing.sink-mappings"
keyChannelTypeMappings = "eventing.channel-type-mappings"
)
@ -86,5 +85,4 @@ const (
// TODO: Remove me if decided that they are not needed
const (
flagPluginsDir = "plugins-dir"
flagPluginsLookupInPath = "lookup-plugins"
)

View File

@ -122,16 +122,13 @@ func TestPluginWithoutLookup(t *testing.T) {
r := test.NewKnRunResultCollector(t, it)
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")
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{})
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"})
t.Log("does not list any other plugin in $PATH")
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
}
func TestPluginInHelpMessage(t *testing.T) {
@ -159,7 +156,7 @@ func TestPluginWithLookup(t *testing.T) {
assert.NilError(t, pc.setup())
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")
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
@ -178,7 +175,7 @@ func TestListPluginInPath(t *testing.T) {
defer tearDownWithPath(pc, oldPath)
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{})
r.DumpIfFailed()
@ -195,7 +192,7 @@ func TestExecutePluginInPath(t *testing.T) {
defer tearDownWithPath(pc, oldPath)
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"})
}
@ -218,11 +215,6 @@ func TestExecutePluginInPathWithError(t *testing.T) {
assert.NilError(t, err)
assert.NilError(t, os.Setenv("PATH", fmt.Sprintf("%s%s%s", oldPath, delim, pluginsDir)))
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