MCPcopy
hub / github.com/digitalocean/doctl / GetStringSlice

Method GetStringSlice

doit.go:425–447  ·  view source on GitHub ↗

GetStringSlice returns a config value as a string slice.

(ns, key string)

Source from the content-addressed store, hash-verified

423
424// GetStringSlice returns a config value as a string slice.
425func (c *LiveConfig) GetStringSlice(ns, key string) ([]string, error) {
426 nskey := nskey(ns, key)
427 val := viper.GetStringSlice(nskey)
428
429 if isRequired(nskey) && emptyStringSlice(val) {
430 return nil, NewMissingArgsErr(nskey)
431 }
432
433 out := []string{}
434 for _, item := range viper.GetStringSlice(nskey) {
435 item = strings.TrimPrefix(item, "[")
436 item = strings.TrimSuffix(item, "]")
437
438 list := strings.Split(item, ",")
439 for _, str := range list {
440 if str == "" {
441 continue
442 }
443 out = append(out, str)
444 }
445 }
446 return out, nil
447}
448
449// GetStringSliceIsFlagSet returns a config value as a string slice and a bool representing the existence of the flag.
450func (c *LiveConfig) GetStringSliceIsFlagSet(ns, key string) ([]string, bool, error) {

Callers 1

Calls 5

nskeyFunction · 0.85
isRequiredFunction · 0.85
emptyStringSliceFunction · 0.85
NewMissingArgsErrFunction · 0.85
GetStringSliceMethod · 0.65

Tested by

no test coverage detected