add more option comments

This commit is contained in:
Jeff
2019-09-12 15:21:47 +08:00
committed by zryfish
parent 66af315a85
commit 5dde737e6c
10 changed files with 98 additions and 41 deletions

View File

@@ -25,6 +25,7 @@ func NewRedisOptions() *RedisOptions {
}
}
// Validate check options
func (r *RedisOptions) Validate() []error {
errors := make([]error, 0)
@@ -34,13 +35,22 @@ func (r *RedisOptions) Validate() []error {
}
}
if r.DB < 0 {
errors = append(errors, fmt.Errorf("--redis-db is less than 0"))
}
return errors
}
// ApplyTo apply to another options if it's a enabled option(non empty host)
func (r *RedisOptions) ApplyTo(options *RedisOptions) {
reflectutils.Override(options, r)
if r.Host != "" {
reflectutils.Override(options, r)
}
}
// AddFlags add option flags to command line flags,
// if redis-host left empty, the following options will be ignored.
func (r *RedisOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&r.Host, "redis-host", r.Host, ""+
"Redis service host address. If left blank, means redis is unnecessary, "+