Set converts, and assigns, the comma-separated IPNet argument string representation as the []net.IPNet value of this flag. If Set is called on a flag that already has a []net.IPNet assigned, the newly converted values will be appended.
(val string)
| 23 | // Set converts, and assigns, the comma-separated IPNet argument string representation as the []net.IPNet value of this flag. |
| 24 | // If Set is called on a flag that already has a []net.IPNet assigned, the newly converted values will be appended. |
| 25 | func (s *ipNetSliceValue) Set(val string) error { |
| 26 | |
| 27 | // remove all quote characters |
| 28 | rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "") |
| 29 | |
| 30 | // read flag arguments with CSV parser |
| 31 | ipNetStrSlice, err := readAsCSV(rmQuote.Replace(val)) |
| 32 | if err != nil && err != io.EOF { |
| 33 | return err |
| 34 | } |
| 35 | |
| 36 | // parse ip values into slice |
| 37 | out := make([]net.IPNet, 0, len(ipNetStrSlice)) |
| 38 | for _, ipNetStr := range ipNetStrSlice { |
| 39 | _, n, err := net.ParseCIDR(strings.TrimSpace(ipNetStr)) |
| 40 | if err != nil { |
| 41 | return fmt.Errorf("invalid string being converted to CIDR: %s", ipNetStr) |
| 42 | } |
| 43 | out = append(out, *n) |
| 44 | } |
| 45 | |
| 46 | if !s.changed { |
| 47 | *s.value = out |
| 48 | } else { |
| 49 | *s.value = append(*s.value, out...) |
| 50 | } |
| 51 | |
| 52 | s.changed = true |
| 53 | |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | // Type returns a string that uniquely represents this flag's type. |
| 58 | func (s *ipNetSliceValue) Type() string { |