Skip to content

Commit 975e8c0

Browse files
committedNov 26, 2022
Change flag.Value to Value
1 parent 2d86e0d commit 975e8c0

13 files changed

+31
-24
lines changed
 

‎flag_bool.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cli
22

33
import (
44
"errors"
5-
"flag"
65
"fmt"
76
"strconv"
87
)
@@ -36,7 +35,7 @@ func (cCtx *Context) Bool(name string) bool {
3635
// Below functions are to satisfy the ValueCreator interface
3736

3837
// Create creates the bool value
39-
func (i boolValue) Create(val bool, p *bool, c BoolConfig) flag.Value {
38+
func (i boolValue) Create(val bool, p *bool, c BoolConfig) Value {
4039
*p = val
4140
if c.Count == nil {
4241
c.Count = new(int)

‎flag_duration.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
"time"
76
)
@@ -13,7 +12,7 @@ type durationValue time.Duration
1312

1413
// Below functions are to satisfy the ValueCreator interface
1514

16-
func (i durationValue) Create(val time.Duration, p *time.Duration, c NoConfig) flag.Value {
15+
func (i durationValue) Create(val time.Duration, p *time.Duration, c NoConfig) Value {
1716
*p = val
1817
return (*durationValue)(p)
1918
}

‎flag_float64.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
"strconv"
76
)
@@ -13,7 +12,7 @@ type float64Value float64
1312

1413
// Below functions are to satisfy the ValueCreator interface
1514

16-
func (f float64Value) Create(val float64, p *float64, c NoConfig) flag.Value {
15+
func (f float64Value) Create(val float64, p *float64, c NoConfig) Value {
1716
*p = val
1817
return (*float64Value)(p)
1918
}

‎flag_impl.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import (
66
"reflect"
77
)
88

9+
type Value interface {
10+
flag.Value
11+
flag.Getter
12+
}
13+
914
// ValueCreator is responsible for creating a flag.Value emulation
1015
// as well as custom formatting
1116
//
1217
// T specifies the type
1318
// C specifies the config for the type
1419
type ValueCreator[T any, C any] interface {
15-
Create(T, *T, C) flag.Value
20+
Create(T, *T, C) Value
1621
ToString(T) string
1722
}
1823

‎flag_int.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
"strconv"
76
)
@@ -21,7 +20,7 @@ type intValue struct {
2120

2221
// Below functions are to satisfy the ValueCreator interface
2322

24-
func (i intValue) Create(val int, p *int, c IntegerConfig) flag.Value {
23+
func (i intValue) Create(val int, p *int, c IntegerConfig) Value {
2524
*p = val
2625
return &intValue{
2726
val: p,

‎flag_int64.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
"strconv"
76
)
@@ -16,7 +15,7 @@ type int64Value struct {
1615

1716
// Below functions are to satisfy the ValueCreator interface
1817

19-
func (i int64Value) Create(val int64, p *int64, c IntegerConfig) flag.Value {
18+
func (i int64Value) Create(val int64, p *int64, c IntegerConfig) Value {
2019
*p = val
2120
return &int64Value{
2221
val: p,

‎flag_slice_impl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
type SliceBase[T any, C any, VC ValueCreator[T, C]] struct {
1313
slice *[]T
1414
hasBeenSet bool
15-
value flag.Value
15+
value Value
1616
}
1717

18-
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) flag.Value {
18+
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) Value {
1919
*p = []T{}
2020
*p = append(*p, val...)
2121
var t T

‎flag_string.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
)
76

@@ -12,7 +11,7 @@ type stringValue string
1211

1312
// Below functions are to satisfy the ValueCreator interface
1413

15-
func (i stringValue) Create(val string, p *string, c NoConfig) flag.Value {
14+
func (i stringValue) Create(val string, p *string, c NoConfig) Value {
1615
*p = val
1716
return (*stringValue)(p)
1817
}

‎flag_timestamp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type timestampValue struct {
2424

2525
// Below functions are to satisfy the ValueCreator interface
2626

27-
func (i timestampValue) Create(val time.Time, p *time.Time, c TimestampConfig) flag.Value {
27+
func (i timestampValue) Create(val time.Time, p *time.Time, c TimestampConfig) Value {
2828
*p = val
2929
return &timestampValue{
3030
timestamp: p,

‎flag_uint.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
"strconv"
76
)
@@ -16,7 +15,7 @@ type uintValue struct {
1615

1716
// Below functions are to satisfy the ValueCreator interface
1817

19-
func (i uintValue) Create(val uint, p *uint, c IntegerConfig) flag.Value {
18+
func (i uintValue) Create(val uint, p *uint, c IntegerConfig) Value {
2019
*p = val
2120
return &uintValue{
2221
val: p,

‎flag_uint64.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"flag"
54
"fmt"
65
"strconv"
76
)
@@ -16,7 +15,7 @@ type uint64Value struct {
1615

1716
// Below functions are to satisfy the ValueCreator interface
1817

19-
func (i uint64Value) Create(val uint64, p *uint64, c IntegerConfig) flag.Value {
18+
func (i uint64Value) Create(val uint64, p *uint64, c IntegerConfig) Value {
2019
*p = val
2120
return &uint64Value{
2221
val: p,

‎godoc-current.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ type SliceBase[T any, C any, VC ValueCreator[T, C]] struct {
963963
func NewSliceBase[T any, C any, VC ValueCreator[T, C]](defaults ...T) *SliceBase[T, C, VC]
964964
NewIntSlice makes an *IntSlice with default values
965965

966-
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) flag.Value
966+
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) Value
967967

968968
func (i *SliceBase[T, C, VC]) Get() interface{}
969969
Get returns the slice of ints set by this flag
@@ -1016,8 +1016,13 @@ type UintSlice = SliceBase[uint, IntegerConfig, uintValue]
10161016

10171017
type UintSliceFlag = FlagBase[[]uint, IntegerConfig, UintSlice]
10181018

1019+
type Value interface {
1020+
flag.Value
1021+
flag.Getter
1022+
}
1023+
10191024
type ValueCreator[T any, C any] interface {
1020-
Create(T, *T, C) flag.Value
1025+
Create(T, *T, C) Value
10211026
ToString(T) string
10221027
}
10231028
ValueCreator is responsible for creating a flag.Value emulation as well as

‎testdata/godoc-v3.x.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ type SliceBase[T any, C any, VC ValueCreator[T, C]] struct {
963963
func NewSliceBase[T any, C any, VC ValueCreator[T, C]](defaults ...T) *SliceBase[T, C, VC]
964964
NewIntSlice makes an *IntSlice with default values
965965

966-
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) flag.Value
966+
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) Value
967967

968968
func (i *SliceBase[T, C, VC]) Get() interface{}
969969
Get returns the slice of ints set by this flag
@@ -1016,8 +1016,13 @@ type UintSlice = SliceBase[uint, IntegerConfig, uintValue]
10161016

10171017
type UintSliceFlag = FlagBase[[]uint, IntegerConfig, UintSlice]
10181018

1019+
type Value interface {
1020+
flag.Value
1021+
flag.Getter
1022+
}
1023+
10191024
type ValueCreator[T any, C any] interface {
1020-
Create(T, *T, C) flag.Value
1025+
Create(T, *T, C) Value
10211026
ToString(T) string
10221027
}
10231028
ValueCreator is responsible for creating a flag.Value emulation as well as

0 commit comments

Comments
 (0)
Please sign in to comment.