MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / fillConfigWithFlags

Function fillConfigWithFlags

rest/config_flags.go:179–319  ·  view source on GitHub ↗

fillConfigWithFlags fills in the config values from registerConfigFlags if the user has explicitly set the flags

(fs *flag.FlagSet, flags map[string]configFlag)

Source from the content-addressed store, hash-verified

177// fillConfigWithFlags fills in the config values from registerConfigFlags if the user
178// has explicitly set the flags
179func fillConfigWithFlags(fs *flag.FlagSet, flags map[string]configFlag) error {
180 var errorMessages *base.MultiError
181 fs.Visit(func(f *flag.Flag) {
182 if val, exists := flags[f.Name]; exists {
183 // force disabled flags to error - we don't want users specifying them at all, even if they are non-functional
184 if val.disabled {
185 errorMessages = errorMessages.Append(fmt.Errorf("command line flag %q is no longer supported and must be removed %s", f.Name, val.disabledErrorMessage))
186 return
187 }
188 rval := reflect.ValueOf(val.config).Elem()
189
190 pointer := true // Distinguish if to use rval.Set or *val.config
191 // Convert to pointer if not already
192 if rval.Kind() != reflect.Ptr && rval.CanAddr() {
193 rval = rval.Addr()
194 pointer = false
195 }
196
197 switch rval.Interface().(type) {
198 case *string:
199 if pointer {
200 rval.Set(reflect.ValueOf(val.flagValue))
201 } else {
202 *val.config.(*string) = *val.flagValue.(*string)
203 }
204 case *[]string:
205 list := strings.Split(*val.flagValue.(*string), ",")
206 *val.config.(*[]string) = list
207 case *[]uint:
208 // split by comma and parse
209 strs := strings.Split(*val.flagValue.(*string), ",")
210 uints := make([]uint, 0, len(strs))
211 for _, s := range strs {
212 u, err := strconv.ParseUint(s, 10, 64)
213 if err != nil {
214 err = fmt.Errorf("flag %s error: %w", f.Name, err)
215 errorMessages = errorMessages.Append(err)
216 return
217 }
218 uints = append(uints, uint(u))
219 }
220 *val.config.(*[]uint) = uints
221 case *uint:
222 if pointer {
223 rval.Set(reflect.ValueOf(val.flagValue))
224 } else {
225 *val.config.(*uint) = *val.flagValue.(*uint)
226 }
227 case *uint64:
228 if pointer {
229 rval.Set(reflect.ValueOf(val.flagValue))
230 } else {
231 *val.config.(*uint64) = *val.flagValue.(*uint64)
232 }
233 case *int:
234 if pointer {
235 rval.Set(reflect.ValueOf(val.flagValue))
236 } else {

Calls 12

AppendMethod · 0.95
UnmarshalTextMethod · 0.95
UnmarshalTextMethod · 0.95
ErrorOrNilMethod · 0.95
JSONDecoderFunction · 0.92
ErrorfMethod · 0.80
DisallowUnknownFieldsMethod · 0.80
DecodeMethod · 0.65
TypeMethod · 0.65
SetMethod · 0.45