Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Value implementations public #223

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type boolFlag interface {
// -- bool Value
type boolValue bool

func newBoolValue(val bool, p *bool) *boolValue {
// NewBoolValue creates bool adapted to be used as flag (with Value interface implementation)
func NewBoolValue(val bool, p *bool) *boolValue {
*p = val
return (*boolValue)(p)
}
Expand Down Expand Up @@ -52,7 +53,7 @@ func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {

// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage)
flag := f.VarPF(NewBoolValue(value, p), name, shorthand, usage)
flag.NoOptDefVal = "true"
}

Expand All @@ -64,7 +65,7 @@ func BoolVar(p *bool, name string, value bool, usage string) {

// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage)
flag := CommandLine.VarPF(NewBoolValue(value, p), name, shorthand, usage)
flag.NoOptDefVal = "true"
}

Expand Down
11 changes: 6 additions & 5 deletions bool_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type boolSliceValue struct {
changed bool
}

func newBoolSliceValue(val []bool, p *[]bool) *boolSliceValue {
// NewBoolSliceValue creates []bool adapted to be used as flag (with Value interface implementation)
func NewBoolSliceValue(val []bool, p *[]bool) *boolSliceValue {
bsv := new(boolSliceValue)
bsv.value = p
*bsv.value = val
Expand Down Expand Up @@ -139,23 +140,23 @@ func (f *FlagSet) GetBoolSlice(name string) ([]bool, error) {
// BoolSliceVar defines a boolSlice flag with specified name, default value, and usage string.
// The argument p points to a []bool variable in which to store the value of the flag.
func (f *FlagSet) BoolSliceVar(p *[]bool, name string, value []bool, usage string) {
f.VarP(newBoolSliceValue(value, p), name, "", usage)
f.VarP(NewBoolSliceValue(value, p), name, "", usage)
}

// BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string) {
f.VarP(newBoolSliceValue(value, p), name, shorthand, usage)
f.VarP(NewBoolSliceValue(value, p), name, shorthand, usage)
}

// BoolSliceVar defines a []bool flag with specified name, default value, and usage string.
// The argument p points to a []bool variable in which to store the value of the flag.
func BoolSliceVar(p *[]bool, name string, value []bool, usage string) {
CommandLine.VarP(newBoolSliceValue(value, p), name, "", usage)
CommandLine.VarP(NewBoolSliceValue(value, p), name, "", usage)
}

// BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string) {
CommandLine.VarP(newBoolSliceValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewBoolSliceValue(value, p), name, shorthand, usage)
}

// BoolSlice defines a []bool flag with specified name, default value, and usage string.
Expand Down
12 changes: 7 additions & 5 deletions bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func (*bytesHexValue) Type() string {
return "bytesHex"
}

func newBytesHexValue(val []byte, p *[]byte) *bytesHexValue {
// NewBytesHexValue creates []byte adapted to be used as flag (with Value interface implementation)
// Value of flag is HEX encoded
func NewBytesHexValue(val []byte, p *[]byte) *bytesHexValue {
*p = val
return (*bytesHexValue)(p)
}
Expand Down Expand Up @@ -63,23 +65,23 @@ func (f *FlagSet) GetBytesHex(name string) ([]byte, error) {
// BytesHexVar defines an []byte flag with specified name, default value, and usage string.
// The argument p points to an []byte variable in which to store the value of the flag.
func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string) {
f.VarP(newBytesHexValue(value, p), name, "", usage)
f.VarP(NewBytesHexValue(value, p), name, "", usage)
}

// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) {
f.VarP(newBytesHexValue(value, p), name, shorthand, usage)
f.VarP(NewBytesHexValue(value, p), name, shorthand, usage)
}

// BytesHexVar defines an []byte flag with specified name, default value, and usage string.
// The argument p points to an []byte variable in which to store the value of the flag.
func BytesHexVar(p *[]byte, name string, value []byte, usage string) {
CommandLine.VarP(newBytesHexValue(value, p), name, "", usage)
CommandLine.VarP(NewBytesHexValue(value, p), name, "", usage)
}

// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) {
CommandLine.VarP(newBytesHexValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewBytesHexValue(value, p), name, shorthand, usage)
}

// BytesHex defines an []byte flag with specified name, default value, and usage string.
Expand Down
6 changes: 4 additions & 2 deletions count.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import "strconv"
// -- count Value
type countValue int

func newCountValue(val int, p *int) *countValue {
// NewCountValue creates counter, that can be used as flag (with Value interface implementation).
// This counter calculates the number of flag appearances in args
func NewCountValue(val int, p *int) *countValue {
*p = val
return (*countValue)(p)
}
Expand Down Expand Up @@ -53,7 +55,7 @@ func (f *FlagSet) CountVar(p *int, name string, usage string) {

// CountVarP is like CountVar only take a shorthand for the flag name.
func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) {
flag := f.VarPF(newCountValue(0, p), name, shorthand, usage)
flag := f.VarPF(NewCountValue(0, p), name, shorthand, usage)
flag.NoOptDefVal = "+1"
}

Expand Down
11 changes: 6 additions & 5 deletions duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
// -- time.Duration Value
type durationValue time.Duration

func newDurationValue(val time.Duration, p *time.Duration) *durationValue {
// NewDurationValue creates time.Duration adapted to be used as flag (with Value interface implementation)
func NewDurationValue(val time.Duration, p *time.Duration) *durationValue {
*p = val
return (*durationValue)(p)
}
Expand Down Expand Up @@ -40,23 +41,23 @@ func (f *FlagSet) GetDuration(name string) (time.Duration, error) {
// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
// The argument p points to a time.Duration variable in which to store the value of the flag.
func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
f.VarP(newDurationValue(value, p), name, "", usage)
f.VarP(NewDurationValue(value, p), name, "", usage)
}

// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
f.VarP(newDurationValue(value, p), name, shorthand, usage)
f.VarP(NewDurationValue(value, p), name, shorthand, usage)
}

// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
// The argument p points to a time.Duration variable in which to store the value of the flag.
func DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
CommandLine.VarP(newDurationValue(value, p), name, "", usage)
CommandLine.VarP(NewDurationValue(value, p), name, "", usage)
}

// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewDurationValue(value, p), name, shorthand, usage)
}

// Duration defines a time.Duration flag with specified name, default value, and usage string.
Expand Down
11 changes: 6 additions & 5 deletions duration_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type durationSliceValue struct {
changed bool
}

func newDurationSliceValue(val []time.Duration, p *[]time.Duration) *durationSliceValue {
// NewDurationSliceValue creates []time.Duration adapted to be used as flag (with Value interface implementation)
func NewDurationSliceValue(val []time.Duration, p *[]time.Duration) *durationSliceValue {
dsv := new(durationSliceValue)
dsv.value = p
*dsv.value = val
Expand Down Expand Up @@ -120,23 +121,23 @@ func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error) {
// DurationSliceVar defines a durationSlice flag with specified name, default value, and usage string.
// The argument p points to a []time.Duration variable in which to store the value of the flag.
func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) {
f.VarP(newDurationSliceValue(value, p), name, "", usage)
f.VarP(NewDurationSliceValue(value, p), name, "", usage)
}

// DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) {
f.VarP(newDurationSliceValue(value, p), name, shorthand, usage)
f.VarP(NewDurationSliceValue(value, p), name, shorthand, usage)
}

// DurationSliceVar defines a duration[] flag with specified name, default value, and usage string.
// The argument p points to a duration[] variable in which to store the value of the flag.
func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) {
CommandLine.VarP(newDurationSliceValue(value, p), name, "", usage)
CommandLine.VarP(NewDurationSliceValue(value, p), name, "", usage)
}

// DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) {
CommandLine.VarP(newDurationSliceValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewDurationSliceValue(value, p), name, shorthand, usage)
}

// DurationSlice defines a []time.Duration flag with specified name, default value, and usage string.
Expand Down
11 changes: 6 additions & 5 deletions float32.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "strconv"
// -- float32 Value
type float32Value float32

func newFloat32Value(val float32, p *float32) *float32Value {
// NewFloat32Value creates float32 adapted to be used as flag (with Value interface implementation)
func NewFloat32Value(val float32, p *float32) *float32Value {
*p = val
return (*float32Value)(p)
}
Expand Down Expand Up @@ -42,23 +43,23 @@ func (f *FlagSet) GetFloat32(name string) (float32, error) {
// Float32Var defines a float32 flag with specified name, default value, and usage string.
// The argument p points to a float32 variable in which to store the value of the flag.
func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) {
f.VarP(newFloat32Value(value, p), name, "", usage)
f.VarP(NewFloat32Value(value, p), name, "", usage)
}

// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
f.VarP(newFloat32Value(value, p), name, shorthand, usage)
f.VarP(NewFloat32Value(value, p), name, shorthand, usage)
}

// Float32Var defines a float32 flag with specified name, default value, and usage string.
// The argument p points to a float32 variable in which to store the value of the flag.
func Float32Var(p *float32, name string, value float32, usage string) {
CommandLine.VarP(newFloat32Value(value, p), name, "", usage)
CommandLine.VarP(NewFloat32Value(value, p), name, "", usage)
}

// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)
CommandLine.VarP(NewFloat32Value(value, p), name, shorthand, usage)
}

// Float32 defines a float32 flag with specified name, default value, and usage string.
Expand Down
11 changes: 6 additions & 5 deletions float32_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type float32SliceValue struct {
changed bool
}

func newFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue {
// NewFloat32SliceValue creates []float32 adapted to be used as flag (with Value interface implementation)
func NewFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue {
isv := new(float32SliceValue)
isv.value = p
*isv.value = val
Expand Down Expand Up @@ -128,23 +129,23 @@ func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error) {
// Float32SliceVar defines a float32Slice flag with specified name, default value, and usage string.
// The argument p points to a []float32 variable in which to store the value of the flag.
func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string) {
f.VarP(newFloat32SliceValue(value, p), name, "", usage)
f.VarP(NewFloat32SliceValue(value, p), name, "", usage)
}

// Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) {
f.VarP(newFloat32SliceValue(value, p), name, shorthand, usage)
f.VarP(NewFloat32SliceValue(value, p), name, shorthand, usage)
}

// Float32SliceVar defines a float32[] flag with specified name, default value, and usage string.
// The argument p points to a float32[] variable in which to store the value of the flag.
func Float32SliceVar(p *[]float32, name string, value []float32, usage string) {
CommandLine.VarP(newFloat32SliceValue(value, p), name, "", usage)
CommandLine.VarP(NewFloat32SliceValue(value, p), name, "", usage)
}

// Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) {
CommandLine.VarP(newFloat32SliceValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewFloat32SliceValue(value, p), name, shorthand, usage)
}

// Float32Slice defines a []float32 flag with specified name, default value, and usage string.
Expand Down
11 changes: 6 additions & 5 deletions float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "strconv"
// -- float64 Value
type float64Value float64

func newFloat64Value(val float64, p *float64) *float64Value {
// NewFloat64Value creates float64 adapted to be used as flag (with Value interface implementation)
func NewFloat64Value(val float64, p *float64) *float64Value {
*p = val
return (*float64Value)(p)
}
Expand Down Expand Up @@ -38,23 +39,23 @@ func (f *FlagSet) GetFloat64(name string) (float64, error) {
// Float64Var defines a float64 flag with specified name, default value, and usage string.
// The argument p points to a float64 variable in which to store the value of the flag.
func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
f.VarP(newFloat64Value(value, p), name, "", usage)
f.VarP(NewFloat64Value(value, p), name, "", usage)
}

// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
f.VarP(newFloat64Value(value, p), name, shorthand, usage)
f.VarP(NewFloat64Value(value, p), name, shorthand, usage)
}

// Float64Var defines a float64 flag with specified name, default value, and usage string.
// The argument p points to a float64 variable in which to store the value of the flag.
func Float64Var(p *float64, name string, value float64, usage string) {
CommandLine.VarP(newFloat64Value(value, p), name, "", usage)
CommandLine.VarP(NewFloat64Value(value, p), name, "", usage)
}

// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)
CommandLine.VarP(NewFloat64Value(value, p), name, shorthand, usage)
}

// Float64 defines a float64 flag with specified name, default value, and usage string.
Expand Down
11 changes: 6 additions & 5 deletions float64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type float64SliceValue struct {
changed bool
}

func newFloat64SliceValue(val []float64, p *[]float64) *float64SliceValue {
// NewFloat64SliceValue creates []float64 adapted to be used as flag (with Value interface implementation)
func NewFloat64SliceValue(val []float64, p *[]float64) *float64SliceValue {
isv := new(float64SliceValue)
isv.value = p
*isv.value = val
Expand Down Expand Up @@ -120,23 +121,23 @@ func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error) {
// Float64SliceVar defines a float64Slice flag with specified name, default value, and usage string.
// The argument p points to a []float64 variable in which to store the value of the flag.
func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string) {
f.VarP(newFloat64SliceValue(value, p), name, "", usage)
f.VarP(NewFloat64SliceValue(value, p), name, "", usage)
}

// Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) {
f.VarP(newFloat64SliceValue(value, p), name, shorthand, usage)
f.VarP(NewFloat64SliceValue(value, p), name, shorthand, usage)
}

// Float64SliceVar defines a float64[] flag with specified name, default value, and usage string.
// The argument p points to a float64[] variable in which to store the value of the flag.
func Float64SliceVar(p *[]float64, name string, value []float64, usage string) {
CommandLine.VarP(newFloat64SliceValue(value, p), name, "", usage)
CommandLine.VarP(NewFloat64SliceValue(value, p), name, "", usage)
}

// Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) {
CommandLine.VarP(newFloat64SliceValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewFloat64SliceValue(value, p), name, shorthand, usage)
}

// Float64Slice defines a []float64 flag with specified name, default value, and usage string.
Expand Down
11 changes: 6 additions & 5 deletions int.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "strconv"
// -- int Value
type intValue int

func newIntValue(val int, p *int) *intValue {
// NewIntValue creates int adapted to be used as flag (with Value interface implementation)
func NewIntValue(val int, p *int) *intValue {
*p = val
return (*intValue)(p)
}
Expand Down Expand Up @@ -38,23 +39,23 @@ func (f *FlagSet) GetInt(name string) (int, error) {
// IntVar defines an int flag with specified name, default value, and usage string.
// The argument p points to an int variable in which to store the value of the flag.
func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
f.VarP(newIntValue(value, p), name, "", usage)
f.VarP(NewIntValue(value, p), name, "", usage)
}

// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) {
f.VarP(newIntValue(value, p), name, shorthand, usage)
f.VarP(NewIntValue(value, p), name, shorthand, usage)
}

// IntVar defines an int flag with specified name, default value, and usage string.
// The argument p points to an int variable in which to store the value of the flag.
func IntVar(p *int, name string, value int, usage string) {
CommandLine.VarP(newIntValue(value, p), name, "", usage)
CommandLine.VarP(NewIntValue(value, p), name, "", usage)
}

// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func IntVarP(p *int, name, shorthand string, value int, usage string) {
CommandLine.VarP(newIntValue(value, p), name, shorthand, usage)
CommandLine.VarP(NewIntValue(value, p), name, shorthand, usage)
}

// Int defines an int flag with specified name, default value, and usage string.
Expand Down
Loading