Skip to content

Commit

Permalink
feat(initializer): set initializer default value to '*' (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoumo authored Mar 5, 2024
1 parent 02633f6 commit 353a131
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions controller/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type InitOption interface {

type options struct {
disableByDefault bool
hidden bool
override bool
}
type optionFunc func(*options)
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 353a131

Please sign in to comment.