MCPcopy Index your code
hub / github.com/docker/cli / Set

Method Set

opts/network.go:43–121  ·  view source on GitHub ↗

Set networkopts value

(value string)

Source from the content-addressed store, hash-verified

41
42// Set networkopts value
43func (n *NetworkOpt) Set(value string) error { //nolint:gocyclo
44 longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value)
45 if err != nil {
46 return err
47 }
48
49 var netOpt NetworkAttachmentOpts
50 if longSyntax {
51 csvReader := csv.NewReader(strings.NewReader(value))
52 fields, err := csvReader.Read()
53 if err != nil {
54 return err
55 }
56
57 netOpt.Aliases = []string{}
58 for _, field := range fields {
59 // TODO(thaJeztah): these options should not be case-insensitive.
60 key, val, ok := strings.Cut(strings.ToLower(field), "=")
61 if !ok || key == "" {
62 return fmt.Errorf("invalid field %s", field)
63 }
64
65 key = strings.TrimSpace(key)
66 val = strings.TrimSpace(val)
67
68 switch key {
69 case networkOptName:
70 netOpt.Target = val
71 case networkOptAlias:
72 netOpt.Aliases = append(netOpt.Aliases, val)
73 case networkOptIPv4Address:
74 netOpt.IPv4Address, err = netip.ParseAddr(val)
75 if err != nil {
76 return err
77 }
78 case networkOptIPv6Address:
79 netOpt.IPv6Address, err = netip.ParseAddr(val)
80 if err != nil {
81 return err
82 }
83 case networkOptMacAddress:
84 netOpt.MacAddress = val
85 case networkOptLinkLocalIP:
86 a, err := netip.ParseAddr(val)
87 if err != nil {
88 return err
89 }
90 netOpt.LinkLocalIPs = append(netOpt.LinkLocalIPs, a)
91 case driverOpt:
92 key, val, err = parseDriverOpt(val)
93 if err != nil {
94 return err
95 }
96 if netOpt.DriverOpts == nil {
97 netOpt.DriverOpts = make(map[string]string)
98 }
99 netOpt.DriverOpts[key] = val
100 case gwPriorityOpt:

Callers 4

TestToServiceNetworkFunction · 0.95

Calls 3

parseDriverOptFunction · 0.85
MatchStringMethod · 0.80
ReadMethod · 0.45

Tested by 4

TestToServiceNetworkFunction · 0.76