Skip to content

Commit

Permalink
Adding Type() method to the values.
Browse files Browse the repository at this point in the history
  • Loading branch information
spf13 committed Jul 11, 2014
1 parent b02196a commit 463bdc8
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (b *boolValue) Set(s string) error {
return err
}

func (b *boolValue) Type() string {
return "bool"
}

func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }

// BoolVar defines a bool flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (d *durationValue) Set(s string) error {
return err
}

func (d *durationValue) Type() string {
return "duration"
}

func (d *durationValue) String() string { return (*time.Duration)(d).String() }

// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
Expand Down
1 change: 1 addition & 0 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type Flag struct {
type Value interface {
String() string
Set(string) error
Type() string
}

// sortFlags returns the flags as a slice in lexicographical sorted order.
Expand Down
4 changes: 4 additions & 0 deletions float32.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (f *float32Value) Set(s string) error {
return err
}

func (f *float32Value) Type() string {
return "float32"
}

func (f *float32Value) String() string { return fmt.Sprintf("%v", *f) }

// Float32Var defines a float32 flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (f *float64Value) Set(s string) error {
return err
}

func (f *float64Value) Type() string {
return "float64"
}

func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }

// Float64Var defines a float64 flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions int.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *intValue) Set(s string) error {
return err
}

func (i *intValue) Type() string {
return "int"
}

func (i *intValue) String() string { return fmt.Sprintf("%v", *i) }

// IntVar defines an int flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions int32.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *int32Value) Set(s string) error {
return err
}

func (i *int32Value) Type() string {
return "int32"
}

func (i *int32Value) String() string { return fmt.Sprintf("%v", *i) }

// Int32Var defines an int32 flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *int64Value) Set(s string) error {
return err
}

func (i *int64Value) Type() string {
return "int64"
}

func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) }

// Int64Var defines an int64 flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions int8.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *int8Value) Set(s string) error {
return err
}

func (i *int8Value) Type() string {
return "int8"
}

func (i *int8Value) String() string { return fmt.Sprintf("%v", *i) }

// Int8Var defines an int8 flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (i *ipValue) Get() interface{} {
return net.IP(*i)
}

func (i *ipValue) Type() string {
return "ip"
}

// 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) {
Expand Down
4 changes: 4 additions & 0 deletions ipmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (i *ipMaskValue) Get() interface{} {
return net.IPMask(*i)
}

func (i *ipMaskValue) Type() string {
return "ipMask"
}

// Parse IPv4 netmask written in IP form (e.g. 255.255.255.0).
// This function should really belong to the net package.
func ParseIPv4Mask(s string) net.IPMask {
Expand Down
3 changes: 3 additions & 0 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func (s *stringValue) Set(val string) error {
*s = stringValue(val)
return nil
}
func (s *stringValue) Type() string {
return "string"
}

func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }

Expand Down
4 changes: 4 additions & 0 deletions uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *uintValue) Set(s string) error {
return err
}

func (i *uintValue) Type() string {
return "uint"
}

func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) }

// UintVar defines a uint flag with specified name, default value, and usage string.
Expand Down
5 changes: 5 additions & 0 deletions uint16.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ func (i *uint16Value) Set(s string) error {
*i = uint16Value(v)
return err
}

func (i *uint16Value) Get() interface{} {
return uint16(*i)
}

func (i *uint16Value) Type() string {
return "uint16"
}

// Uint16Var defines a uint flag with specified name, default value, and usage string.
// The argument p points to a uint variable in which to store the value of the flag.
func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) {
Expand Down
4 changes: 4 additions & 0 deletions uint32.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (i *uint32Value) Get() interface{} {
return uint32(*i)
}

func (i *uint32Value) Type() string {
return "uint32"
}

// Uint32Var defines a uint32 flag with specified name, default value, and usage string.
// The argument p points to a uint32 variable in which to store the value of the flag.
func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) {
Expand Down
4 changes: 4 additions & 0 deletions uint64.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *uint64Value) Set(s string) error {
return err
}

func (i *uint64Value) Type() string {
return "uint64"
}

func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) }

// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
Expand Down
4 changes: 4 additions & 0 deletions uint8.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (i *uint8Value) Set(s string) error {
return err
}

func (i *uint8Value) Type() string {
return "uint8"
}

func (i *uint8Value) String() string { return fmt.Sprintf("%v", *i) }

// Uint8Var defines a uint8 flag with specified name, default value, and usage string.
Expand Down

0 comments on commit 463bdc8

Please sign in to comment.