diff options
author | Victor Häggqvist <[email protected]> | 2018-03-05 22:19:22 +0100 |
---|---|---|
committer | Victor Häggqvist <[email protected]> | 2018-03-05 22:19:22 +0100 |
commit | f96b7fc1e15ad88c80814e6b153c74453098f499 (patch) | |
tree | 92813eab3a38ad4f177bedef5e5c402bec8a9699 /vendor/github.com/victorhaggqvist/pflag/ip.go | |
parent | 6e1582f6e7f4148c25e58dc44a080d441e95db85 (diff) |
update vendor to use dep
Diffstat (limited to '')
-rw-r--r-- | vendor/github.com/victorhaggqvist/pflag/ip.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/victorhaggqvist/pflag/ip.go b/vendor/github.com/victorhaggqvist/pflag/ip.go new file mode 100644 index 0000000..3a411fc --- /dev/null +++ b/vendor/github.com/victorhaggqvist/pflag/ip.go @@ -0,0 +1,75 @@ +package pflag + +import ( + "fmt" + "net" +) + +// -- net.IP value +type ipValue net.IP + +func newIPValue(val net.IP, p *net.IP) *ipValue { + *p = val + return (*ipValue)(p) +} + +func (i *ipValue) String() string { return net.IP(*i).String() } +func (i *ipValue) Set(s string) error { + ip := net.ParseIP(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) +} + +// IPVar defines an net.IP flag with specified name, default value, and usage string. +// The argument p points to an net.IP variable in which to store the value of the flag. +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. +func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { + f.VarP(newIPValue(value, p), name, shorthand, usage) +} + +// IPVar defines an net.IP flag with specified name, default value, and usage string. +// The argument p points to an net.IP variable in which to store the value of the flag. +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. +func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { + CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) +} + +// IP defines an net.IP flag with specified name, default value, and usage string. +// The return value is the address of an net.IP variable that stores the value of the flag. +func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { + p := new(net.IP) + f.IPVarP(p, name, "", value, usage) + return p +} + +// 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) + return p +} + +// IP defines an net.IP flag with specified name, default value, and usage string. +// The return value is the address of an net.IP variable that stores the value of the flag. +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. +func IPP(name, shorthand string, value net.IP, usage string) *net.IP { + return CommandLine.IPP(name, shorthand, value, usage) +} |