12 func newIPValue(val net.IP, p *net.IP) *ipValue {
17 func (i *ipValue) String() string { return net.IP(*i).String() }
18 func (i *ipValue) Set(s string) error {
19 ip := net.ParseIP(strings.TrimSpace(s))
21 return fmt.Errorf("failed to parse IP: %q", s)
27 func (i *ipValue) Type() string {
31 func ipConv(sval string) (interface{}, error) {
32 ip := net.ParseIP(sval)
36 return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval)
39 // GetIP return the net.IP value of a flag with the given name
40 func (f *FlagSet) GetIP(name string) (net.IP, error) {
41 val, err := f.getFlagType(name, "ip", ipConv)
45 return val.(net.IP), nil
48 // IPVar defines an net.IP flag with specified name, default value, and usage string.
49 // The argument p points to an net.IP variable in which to store the value of the flag.
50 func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) {
51 f.VarP(newIPValue(value, p), name, "", usage)
54 // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
55 func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
56 f.VarP(newIPValue(value, p), name, shorthand, usage)
59 // IPVar defines an net.IP flag with specified name, default value, and usage string.
60 // The argument p points to an net.IP variable in which to store the value of the flag.
61 func IPVar(p *net.IP, name string, value net.IP, usage string) {
62 CommandLine.VarP(newIPValue(value, p), name, "", usage)
65 // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
66 func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
67 CommandLine.VarP(newIPValue(value, p), name, shorthand, usage)
70 // IP defines an net.IP flag with specified name, default value, and usage string.
71 // The return value is the address of an net.IP variable that stores the value of the flag.
72 func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP {
74 f.IPVarP(p, name, "", value, usage)
78 // IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
79 func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP {
81 f.IPVarP(p, name, shorthand, value, usage)
85 // IP defines an net.IP flag with specified name, default value, and usage string.
86 // The return value is the address of an net.IP variable that stores the value of the flag.
87 func IP(name string, value net.IP, usage string) *net.IP {
88 return CommandLine.IPP(name, "", value, usage)
91 // IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
92 func IPP(name, shorthand string, value net.IP, usage string) *net.IP {
93 return CommandLine.IPP(name, shorthand, value, usage)