From 353a1319389d04c991baa1f5f175761495f99667 Mon Sep 17 00:00:00 2001 From: zoumo Date: Tue, 5 Mar 2024 20:30:37 +0800 Subject: [PATCH] feat(initializer): set initializer default value to '*' (#32) --- controller/initializer/initializer.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/controller/initializer/initializer.go b/controller/initializer/initializer.go index f409aff..e6c66af 100644 --- a/controller/initializer/initializer.go +++ b/controller/initializer/initializer.go @@ -41,7 +41,6 @@ type InitOption interface { type options struct { disableByDefault bool - hidden bool override bool } type optionFunc func(*options) @@ -140,7 +139,7 @@ func (m *managerInitializer) Add(name string, setup InitFunc, opts ...InitOption m.all.Insert(name) - if opt.disableByDefault && !opt.hidden { + if opt.disableByDefault { m.disableByDefault.Insert(name) } else { m.enabled.Insert(name) @@ -153,10 +152,18 @@ func (m *managerInitializer) Add(name string, setup InitFunc, opts ...InitOption func (m *managerInitializer) BindFlag(fs *pflag.FlagSet) { all := m.all.List() disabled := m.disableByDefault.List() - fs.Var(m, m.name, fmt.Sprintf(""+ - "A list of %s to enable. '*' enables all on-by-default %s, 'foo' enables the %s "+ - "named 'foo', '-foo' disables the %s named 'foo'.\nAll: %s\nDisabled-by-default: %s", - m.name, m.name, m.name, m.name, strings.Join(all, ", "), strings.Join(disabled, ", "))) + + usage := fmt.Sprintf(""+ + "A list of %s to enable.\n"+ + "'*' enables all on-by-default %s.\n"+ + "'foo' enables the %s named 'foo'.\n"+ + "'-foo' disables the %s named 'foo'.\n"+ + "All: '%s'\n"+ + "Disabled-by-default: '%s'\n", + m.name, m.name, m.name, m.name, strings.Join(all, ", "), strings.Join(disabled, ", ")) + + flag := fs.VarPF(m, m.name, "", usage) + flag.DefValue = "*" } // Knowns implements Controllerinitializer.