-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve custom config flag handlers #5543
Conversation
libbeat/common/flags.go
Outdated
return f.List() | ||
} | ||
|
||
func (f *StringsFlag) List() []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.List should have comment or be unexported
libbeat/common/flags.go
Outdated
return nil | ||
} | ||
|
||
func (f *StringsFlag) Get() interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.Get should have comment or be unexported
libbeat/common/flags.go
Outdated
} | ||
} | ||
|
||
func (f *StringsFlag) Set(v string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.Set should have comment or be unexported
libbeat/common/flags.go
Outdated
return strings.Join(*f.list, ", ") | ||
} | ||
|
||
func (f StringsFlag) SetDefault(v string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.SetDefault should have comment or be unexported
libbeat/common/flags.go
Outdated
return StringArrVarFlag(arr, name, usage) | ||
} | ||
|
||
func StringArrVarFlag(arr *[]string, name, usage string) *StringsFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function StringArrVarFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
flag *flag.Flag | ||
} | ||
|
||
func StringArrFlag(name, def, usage string) *StringsFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function StringArrFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
"strings" | ||
) | ||
|
||
type StringsFlag struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type StringsFlag should have comment or be unexported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Maybe fix the hound complains?
The failures seems to be unrelated.
--- FAIL: TestFetch (81.44s)
Error Trace: status_integration_test.go:20
Error: Received unexpected error "error making http request: Get http://kibana:5601/api/status: lookup kibana
assert.Equal(t, test.expected, flag.List()) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wohoo tests :)
libbeat/common/flags.go
Outdated
return *f.list | ||
} | ||
|
||
func (f *StringsFlag) Type() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.Type should have comment or be unexported
libbeat/common/flags.go
Outdated
return strings.Join(l, ", ") | ||
} | ||
|
||
func (f *StringsFlag) SetDefault(v string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.SetDefault should have comment or be unexported
libbeat/common/flags.go
Outdated
return &StringsFlag{list: arr, isDefault: true} | ||
} | ||
|
||
func (f *StringsFlag) Register(fs *flag.FlagSet, name, usage string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.Register should have comment or be unexported
libbeat/common/flags.go
Outdated
return f | ||
} | ||
|
||
func NewStringsFlag(arr *[]string) *StringsFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function NewStringsFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
return *f.list | ||
} | ||
|
||
func (f *StringsFlag) Type() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.Type should have comment or be unexported
libbeat/common/flags.go
Outdated
return strings.Join(l, ", ") | ||
} | ||
|
||
func (f *StringsFlag) SetDefault(v string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.SetDefault should have comment or be unexported
libbeat/common/flags.go
Outdated
return &StringsFlag{list: arr, isDefault: true} | ||
} | ||
|
||
func (f *StringsFlag) Register(fs *flag.FlagSet, name, usage string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method StringsFlag.Register should have comment or be unexported
libbeat/common/flags.go
Outdated
return f | ||
} | ||
|
||
func NewStringsFlag(arr *[]string) *StringsFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function NewStringsFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
return "setting=value" | ||
} | ||
|
||
func ConfigOverwriteFlag( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function ConfigOverwriteFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
return "" | ||
} | ||
|
||
func (f *SettingsFlag) Type() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method SettingsFlag.Type should have comment or be unexported
libbeat/common/flags.go
Outdated
return f.access().Set(s) | ||
} | ||
|
||
func (f *SettingsFlag) Get() interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method SettingsFlag.Get should have comment or be unexported
libbeat/common/flags.go
Outdated
return fromConfig(f.access().Config()) | ||
} | ||
|
||
func (f *SettingsFlag) Set(s string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method SettingsFlag.Set should have comment or be unexported
libbeat/common/flags.go
Outdated
return (*cfgflag.FlagValue)(f) | ||
} | ||
|
||
func (f *SettingsFlag) Config() *Config { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method SettingsFlag.Config should have comment or be unexported
libbeat/common/flags.go
Outdated
fs.Var(f, name, usage) | ||
} | ||
|
||
func NewSettingsFlag(def *Config) *SettingsFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function NewSettingsFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
return cfg | ||
} | ||
|
||
func SettingVarFlag(fs *flag.FlagSet, def *Config, name, usage string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function SettingVarFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
return "string" | ||
} | ||
|
||
func SettingFlag(fs *flag.FlagSet, name, usage string) *Config { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function SettingFlag should have comment or be unexported
libbeat/common/flags.go
Outdated
return StringArrVarFlag(fs, arr, name, usage) | ||
} | ||
|
||
func StringArrVarFlag(fs *flag.FlagSet, arr *[]string, name, usage string) *StringsFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function StringArrVarFlag should have comment or be unexported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, waiting on CI to merge that.
+1 on refactoring
+1 on adding test
+100 for user facing improvement :)
@urso Would you mind squashing it? |
ff58fb3
to
138b48f
Compare
- move support for flags collecting usage into a []string to libbeat/common - fix printing default value of `-c` flag - move flags manipulating config objects from config.go to flags.go - change flag namings to always end with xxxFlag - introduce unit tests for config flags - check the flags usage string in unit tests - fix potential panic when printing defaults on flag collecting into []string (nil pointer being passed) - fix printing defaults and setting types - add `Type` method improving cobra flag parameter in help message Old flags usage messages for `filebeat -h`: ``` -E, --E Flag Configuration overwrite (default null) -M, --M Flag Module configuration overwrite (default null) -N, --N Disable actual publishing for testing -c, --c argList Configuration file, relative to path.config (default beat.yml) --cpuprofile string Write cpu profile to file -d, --d string Enable certain debug selectors -e, --e Log to stderr and disable syslog/file output -h, --help help for filebeat --httpprof string Start pprof http server --memprofile string Write memory profile to this file --modules string List of enabled modules (comma separated) --once Run filebeat only once until all harvesters reach EOF --path.config flagOverwrite Configuration path --path.data flagOverwrite Data path --path.home flagOverwrite Home path --path.logs flagOverwrite Logs path --setup Load the sample Kibana dashboards --strict.perms Strict permission checking on config files (default true) -v, --v Log at INFO level ``` New flags usage messages for `filebeat -h`: ``` -E, --E setting=value Configuration overwrite -M, --M setting=value Module configuration overwrite -N, --N Disable actual publishing for testing -c, --c string Configuration file, relative to path.config (default "filebeat.yml") --cpuprofile string Write cpu profile to file -d, --d string Enable certain debug selectors -e, --e Log to stderr and disable syslog/file output -h, --help help for filebeat --httpprof string Start pprof http server --memprofile string Write memory profile to this file --modules string List of enabled modules (comma separated) --once Run filebeat only once until all harvesters reach EOF --path.config string Configuration path --path.data string Data path --path.home string Home path --path.logs string Logs path --setup Load the sample Kibana dashboards --strict.perms Strict permission checking on config files (default true) -v, --v Log at INFO level ```
138b48f
to
21da625
Compare
-c
flagType
method improving cobra flag parameter in help messageOld flags usage messages for
filebeat -h
:New flags usage messages for
filebeat -h
: