summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/pflag/ip.go
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2020-04-21 09:34:44 +0200
committerVictor Häggqvist <[email protected]>2020-04-21 09:34:44 +0200
commitd21f39eeebd3586e7faf4d83c7a8e12b6e04c82e (patch)
tree1793d726cd50cb2d3a4311d8bb38fbf3fbdeda12 /vendor/github.com/spf13/pflag/ip.go
parentd0a84f15f765383e077fee487af61c0e2e6bdf6d (diff)
replace ini
Diffstat (limited to '')
-rw-r--r--vendor/github.com/spf13/pflag/ip.go (renamed from vendor/github.com/victorhaggqvist/pflag/ip.go)33
1 files changed, 26 insertions, 7 deletions
diff --git a/vendor/github.com/victorhaggqvist/pflag/ip.go b/vendor/github.com/spf13/pflag/ip.go
index 3a411fc..3d414ba 100644
--- a/vendor/github.com/victorhaggqvist/pflag/ip.go
+++ b/vendor/github.com/spf13/pflag/ip.go
@@ -3,6 +3,7 @@ package pflag
import (
"fmt"
"net"
+ "strings"
)
// -- net.IP value
@@ -15,15 +16,33 @@ func newIPValue(val net.IP, p *net.IP) *ipValue {
func (i *ipValue) String() string { return net.IP(*i).String() }
func (i *ipValue) Set(s string) error {
- ip := net.ParseIP(s)
+ ip := net.ParseIP(strings.TrimSpace(s))
if ip == nil {
return fmt.Errorf("failed to parse IP: %q", s)
}
*i = ipValue(ip)
return nil
}
-func (i *ipValue) Get() interface{} {
- return net.IP(*i)
+
+func (i *ipValue) Type() string {
+ return "ip"
+}
+
+func ipConv(sval string) (interface{}, error) {
+ ip := net.ParseIP(sval)
+ if ip != nil {
+ return ip, nil
+ }
+ return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval)
+}
+
+// GetIP return the net.IP value of a flag with the given name
+func (f *FlagSet) GetIP(name string) (net.IP, error) {
+ val, err := f.getFlagType(name, "ip", ipConv)
+ if err != nil {
+ return nil, err
+ }
+ return val.(net.IP), nil
}
// IPVar defines an net.IP flag with specified name, default value, and usage string.
@@ -32,7 +51,7 @@ func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) {
f.VarP(newIPValue(value, p), name, "", usage)
}
-// Like IPVar, but accepts a shorthand letter that can be used after a single dash.
+// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
f.VarP(newIPValue(value, p), name, shorthand, usage)
}
@@ -43,7 +62,7 @@ func IPVar(p *net.IP, name string, value net.IP, usage string) {
CommandLine.VarP(newIPValue(value, p), name, "", usage)
}
-// Like IPVar, but accepts a shorthand letter that can be used after a single dash.
+// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
CommandLine.VarP(newIPValue(value, p), name, shorthand, usage)
}
@@ -56,7 +75,7 @@ func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP {
return p
}
-// Like IP, but accepts a shorthand letter that can be used after a single dash.
+// IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP {
p := new(net.IP)
f.IPVarP(p, name, shorthand, value, usage)
@@ -69,7 +88,7 @@ func IP(name string, value net.IP, usage string) *net.IP {
return CommandLine.IPP(name, "", value, usage)
}
-// Like IP, but accepts a shorthand letter that can be used after a single dash.
+// IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPP(name, shorthand string, value net.IP, usage string) *net.IP {
return CommandLine.IPP(name, shorthand, value, usage)
}