Set converts, and assigns, the comma-separated IP argument string representation as the []net.IP value of this flag. If Set is called on a flag that already has a []net.IP assigned, the newly converted values will be appended.
(val string)
| 23 | // Set converts, and assigns, the comma-separated IP argument string representation as the []net.IP value of this flag. |
| 24 | // If Set is called on a flag that already has a []net.IP assigned, the newly converted values will be appended. |
| 25 | func (s *ipSliceValue) Set(val string) error { |
| 26 | |
| 27 | // remove all quote characters |
| 28 | rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "") |
| 29 | |
| 30 | // read flag arguments with CSV parser |
| 31 | ipStrSlice, 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.IP, 0, len(ipStrSlice)) |
| 38 | for _, ipStr := range ipStrSlice { |
| 39 | ip := net.ParseIP(strings.TrimSpace(ipStr)) |
| 40 | if ip == nil { |
| 41 | return fmt.Errorf("invalid string being converted to IP address: %s", ipStr) |
| 42 | } |
| 43 | out = append(out, ip) |
| 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 *ipSliceValue) Type() string { |