MCPcopy Create free account
hub / github.com/docker/cli / transformListOrMapping

Function transformListOrMapping

cli/compose/loader/loader.go:822–848  ·  view source on GitHub ↗

transformListOrMapping transforms pairs of strings that may be represented as a map, or a list of '=' or ':' separated strings, into a list of ':' separated strings.

(listOrMapping any, sep string, allowNil bool, allowSeps []string)

Source from the content-addressed store, hash-verified

820// a map, or a list of '=' or ':' separated strings, into a list of ':' separated
821// strings.
822func transformListOrMapping(listOrMapping any, sep string, allowNil bool, allowSeps []string) []string {
823 switch value := listOrMapping.(type) {
824 case map[string]any:
825 return toStringList(value, sep, allowNil)
826 case []any:
827 result := make([]string, 0, len(value))
828 for _, entry := range value {
829 for i, allowSep := range allowSeps {
830 entry := fmt.Sprint(entry)
831 k, v, ok := strings.Cut(entry, allowSep)
832 if ok {
833 // Entry uses this allowed separator. Add it to the result, using
834 // sep as a separator.
835 result = append(result, fmt.Sprintf("%s%s%s", k, sep, v))
836 break
837 } else if i == len(allowSeps)-1 {
838 // No more separators to try, keep the entry if allowNil.
839 if allowNil {
840 result = append(result, k)
841 }
842 }
843 }
844 }
845 return result
846 }
847 panic(fmt.Errorf("expected a map or a list, got %T: %#v", listOrMapping, listOrMapping))
848}
849
850func transformMappingOrListFunc(sep string, allowNil bool) TransformerFunc {
851 return func(data any) (any, error) {

Callers 1

loader.goFile · 0.85

Calls 2

toStringListFunction · 0.85
SprintMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…