Skip to content
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
22 changes: 11 additions & 11 deletions bool_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (
)

// -- boolSlice Value
type boolSliceValue struct {
type BoolSliceValue struct {
value *[]bool
changed bool
}

func newBoolSliceValue(val []bool, p *[]bool) *boolSliceValue {
bsv := new(boolSliceValue)
func newBoolSliceValue(val []bool, p *[]bool) *BoolSliceValue {
bsv := new(BoolSliceValue)
bsv.value = p
*bsv.value = val
return bsv
}

// Set converts, and assigns, the comma-separated boolean argument string representation as the []bool value of this flag.
// If Set is called on a flag that already has a []bool assigned, the newly converted values will be appended.
func (s *boolSliceValue) Set(val string) error {
func (s *BoolSliceValue) Set(val string) error {

// remove all quote characters
rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "")
Expand Down Expand Up @@ -54,12 +54,12 @@ func (s *boolSliceValue) Set(val string) error {
}

// Type returns a string that uniquely represents this flag's type.
func (s *boolSliceValue) Type() string {
func (s *BoolSliceValue) Type() string {
return "boolSlice"
}

// String defines a "native" format for this boolean slice flag value.
func (s *boolSliceValue) String() string {
func (s *BoolSliceValue) String() string {

boolStrSlice := make([]string, len(*s.value))
for i, b := range *s.value {
Expand All @@ -71,15 +71,15 @@ func (s *boolSliceValue) String() string {
return "[" + out + "]"
}

func (s *boolSliceValue) fromString(val string) (bool, error) {
func (s *BoolSliceValue) fromString(val string) (bool, error) {
return strconv.ParseBool(val)
}

func (s *boolSliceValue) toString(val bool) string {
func (s *BoolSliceValue) toString(val bool) string {
return strconv.FormatBool(val)
}

func (s *boolSliceValue) Append(val string) error {
func (s *BoolSliceValue) Append(val string) error {
i, err := s.fromString(val)
if err != nil {
return err
Expand All @@ -88,7 +88,7 @@ func (s *boolSliceValue) Append(val string) error {
return nil
}

func (s *boolSliceValue) Replace(val []string) error {
func (s *BoolSliceValue) Replace(val []string) error {
out := make([]bool, len(val))
for i, d := range val {
var err error
Expand All @@ -101,7 +101,7 @@ func (s *boolSliceValue) Replace(val []string) error {
return nil
}

func (s *boolSliceValue) GetSlice() []string {
func (s *BoolSliceValue) GetSlice() []string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = s.toString(d)
Expand Down
22 changes: 11 additions & 11 deletions duration_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

// -- durationSlice Value
type durationSliceValue struct {
type DurationSliceValue struct {
value *[]time.Duration
changed bool
}

func newDurationSliceValue(val []time.Duration, p *[]time.Duration) *durationSliceValue {
dsv := new(durationSliceValue)
func newDurationSliceValue(val []time.Duration, p *[]time.Duration) *DurationSliceValue {
dsv := new(DurationSliceValue)
dsv.value = p
*dsv.value = val
return dsv
}

func (s *durationSliceValue) Set(val string) error {
func (s *DurationSliceValue) Set(val string) error {
ss := strings.Split(val, ",")
out := make([]time.Duration, len(ss))
for i, d := range ss {
Expand All @@ -39,27 +39,27 @@ func (s *durationSliceValue) Set(val string) error {
return nil
}

func (s *durationSliceValue) Type() string {
func (s *DurationSliceValue) Type() string {
return "durationSlice"
}

func (s *durationSliceValue) String() string {
func (s *DurationSliceValue) String() string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = fmt.Sprintf("%s", d)
}
return "[" + strings.Join(out, ",") + "]"
}

func (s *durationSliceValue) fromString(val string) (time.Duration, error) {
func (s *DurationSliceValue) fromString(val string) (time.Duration, error) {
return time.ParseDuration(val)
}

func (s *durationSliceValue) toString(val time.Duration) string {
func (s *DurationSliceValue) toString(val time.Duration) string {
return fmt.Sprintf("%s", val)
}

func (s *durationSliceValue) Append(val string) error {
func (s *DurationSliceValue) Append(val string) error {
i, err := s.fromString(val)
if err != nil {
return err
Expand All @@ -68,7 +68,7 @@ func (s *durationSliceValue) Append(val string) error {
return nil
}

func (s *durationSliceValue) Replace(val []string) error {
func (s *DurationSliceValue) Replace(val []string) error {
out := make([]time.Duration, len(val))
for i, d := range val {
var err error
Expand All @@ -81,7 +81,7 @@ func (s *durationSliceValue) Replace(val []string) error {
return nil
}

func (s *durationSliceValue) GetSlice() []string {
func (s *DurationSliceValue) GetSlice() []string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = s.toString(d)
Expand Down
4 changes: 2 additions & 2 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ func (f *Flag) defaultIsZeroValue() bool {
return f.DefValue == "0" || f.DefValue == "0s"
case *intValue, *int8Value, *int32Value, *int64Value, *uintValue, *uint8Value, *uint16Value, *uint32Value, *uint64Value, *countValue, *float32Value, *float64Value:
return f.DefValue == "0"
case *stringValue:
case *StringValue:
return f.DefValue == ""
case *ipValue, *ipMaskValue, *ipNetValue:
return f.DefValue == "<nil>"
case *intSliceValue, *stringSliceValue, *stringArrayValue:
case *IntSliceValue, *StringSliceValue, *StringArrayValue:
return f.DefValue == "[]"
default:
switch f.Value.String() {
Expand Down
22 changes: 11 additions & 11 deletions float32_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

// -- float32Slice Value
type float32SliceValue struct {
type Float32SliceValue struct {
value *[]float32
changed bool
}

func newFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue {
isv := new(float32SliceValue)
func newFloat32SliceValue(val []float32, p *[]float32) *Float32SliceValue {
isv := new(Float32SliceValue)
isv.value = p
*isv.value = val
return isv
}

func (s *float32SliceValue) Set(val string) error {
func (s *Float32SliceValue) Set(val string) error {
ss := strings.Split(val, ",")
out := make([]float32, len(ss))
for i, d := range ss {
Expand All @@ -41,31 +41,31 @@ func (s *float32SliceValue) Set(val string) error {
return nil
}

func (s *float32SliceValue) Type() string {
func (s *Float32SliceValue) Type() string {
return "float32Slice"
}

func (s *float32SliceValue) String() string {
func (s *Float32SliceValue) String() string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = fmt.Sprintf("%f", d)
}
return "[" + strings.Join(out, ",") + "]"
}

func (s *float32SliceValue) fromString(val string) (float32, error) {
func (s *Float32SliceValue) fromString(val string) (float32, error) {
t64, err := strconv.ParseFloat(val, 32)
if err != nil {
return 0, err
}
return float32(t64), nil
}

func (s *float32SliceValue) toString(val float32) string {
func (s *Float32SliceValue) toString(val float32) string {
return fmt.Sprintf("%f", val)
}

func (s *float32SliceValue) Append(val string) error {
func (s *Float32SliceValue) Append(val string) error {
i, err := s.fromString(val)
if err != nil {
return err
Expand All @@ -74,7 +74,7 @@ func (s *float32SliceValue) Append(val string) error {
return nil
}

func (s *float32SliceValue) Replace(val []string) error {
func (s *Float32SliceValue) Replace(val []string) error {
out := make([]float32, len(val))
for i, d := range val {
var err error
Expand All @@ -87,7 +87,7 @@ func (s *float32SliceValue) Replace(val []string) error {
return nil
}

func (s *float32SliceValue) GetSlice() []string {
func (s *Float32SliceValue) GetSlice() []string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = s.toString(d)
Expand Down
22 changes: 11 additions & 11 deletions float64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

// -- float64Slice Value
type float64SliceValue struct {
type Float64SliceValue struct {
value *[]float64
changed bool
}

func newFloat64SliceValue(val []float64, p *[]float64) *float64SliceValue {
isv := new(float64SliceValue)
func newFloat64SliceValue(val []float64, p *[]float64) *Float64SliceValue {
isv := new(Float64SliceValue)
isv.value = p
*isv.value = val
return isv
}

func (s *float64SliceValue) Set(val string) error {
func (s *Float64SliceValue) Set(val string) error {
ss := strings.Split(val, ",")
out := make([]float64, len(ss))
for i, d := range ss {
Expand All @@ -39,27 +39,27 @@ func (s *float64SliceValue) Set(val string) error {
return nil
}

func (s *float64SliceValue) Type() string {
func (s *Float64SliceValue) Type() string {
return "float64Slice"
}

func (s *float64SliceValue) String() string {
func (s *Float64SliceValue) String() string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = fmt.Sprintf("%f", d)
}
return "[" + strings.Join(out, ",") + "]"
}

func (s *float64SliceValue) fromString(val string) (float64, error) {
func (s *Float64SliceValue) fromString(val string) (float64, error) {
return strconv.ParseFloat(val, 64)
}

func (s *float64SliceValue) toString(val float64) string {
func (s *Float64SliceValue) toString(val float64) string {
return fmt.Sprintf("%f", val)
}

func (s *float64SliceValue) Append(val string) error {
func (s *Float64SliceValue) Append(val string) error {
i, err := s.fromString(val)
if err != nil {
return err
Expand All @@ -68,7 +68,7 @@ func (s *float64SliceValue) Append(val string) error {
return nil
}

func (s *float64SliceValue) Replace(val []string) error {
func (s *Float64SliceValue) Replace(val []string) error {
out := make([]float64, len(val))
for i, d := range val {
var err error
Expand All @@ -81,7 +81,7 @@ func (s *float64SliceValue) Replace(val []string) error {
return nil
}

func (s *float64SliceValue) GetSlice() []string {
func (s *Float64SliceValue) GetSlice() []string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = s.toString(d)
Expand Down
22 changes: 11 additions & 11 deletions int32_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

// -- int32Slice Value
type int32SliceValue struct {
type Int32SliceValue struct {
value *[]int32
changed bool
}

func newInt32SliceValue(val []int32, p *[]int32) *int32SliceValue {
isv := new(int32SliceValue)
func newInt32SliceValue(val []int32, p *[]int32) *Int32SliceValue {
isv := new(Int32SliceValue)
isv.value = p
*isv.value = val
return isv
}

func (s *int32SliceValue) Set(val string) error {
func (s *Int32SliceValue) Set(val string) error {
ss := strings.Split(val, ",")
out := make([]int32, len(ss))
for i, d := range ss {
Expand All @@ -41,31 +41,31 @@ func (s *int32SliceValue) Set(val string) error {
return nil
}

func (s *int32SliceValue) Type() string {
func (s *Int32SliceValue) Type() string {
return "int32Slice"
}

func (s *int32SliceValue) String() string {
func (s *Int32SliceValue) String() string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = fmt.Sprintf("%d", d)
}
return "[" + strings.Join(out, ",") + "]"
}

func (s *int32SliceValue) fromString(val string) (int32, error) {
func (s *Int32SliceValue) fromString(val string) (int32, error) {
t64, err := strconv.ParseInt(val, 0, 32)
if err != nil {
return 0, err
}
return int32(t64), nil
}

func (s *int32SliceValue) toString(val int32) string {
func (s *Int32SliceValue) toString(val int32) string {
return fmt.Sprintf("%d", val)
}

func (s *int32SliceValue) Append(val string) error {
func (s *Int32SliceValue) Append(val string) error {
i, err := s.fromString(val)
if err != nil {
return err
Expand All @@ -74,7 +74,7 @@ func (s *int32SliceValue) Append(val string) error {
return nil
}

func (s *int32SliceValue) Replace(val []string) error {
func (s *Int32SliceValue) Replace(val []string) error {
out := make([]int32, len(val))
for i, d := range val {
var err error
Expand All @@ -87,7 +87,7 @@ func (s *int32SliceValue) Replace(val []string) error {
return nil
}

func (s *int32SliceValue) GetSlice() []string {
func (s *Int32SliceValue) GetSlice() []string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = s.toString(d)
Expand Down
Loading