Skip to content

Commit 23f3c5c

Browse files
committed
Add tests
1 parent 3d0a05b commit 23f3c5c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flag_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type FlagBase[T any, C any, VC ValueCreator[T, C]] struct {
9292
// GetValue returns the flags value as string representation and an empty
9393
// string if the flag takes no value at all.
9494
func (f *FlagBase[T, C, V]) GetValue() string {
95-
if reflect.TypeOf(f.Value).Kind() == reflect.Bool {
95+
if !f.TakesValue() {
9696
return ""
9797
}
9898
return fmt.Sprintf("%v", f.Value)

flag_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,3 +3127,9 @@ func TestEnvHintWindows(t *testing.T) {
31273127
assert.Equal(t, "something [%foo%, %bar%, %ss%]", withEnvHint([]string{"foo", "bar", "ss"}, "something"))
31283128
}
31293129
}
3130+
3131+
func TestDocGetValue(t *testing.T) {
3132+
assert.Equal(t, "", (&BoolFlag{Name: "foo", Value: true}).GetValue())
3133+
assert.Equal(t, "", (&BoolFlag{Name: "foo", Value: false}).GetValue())
3134+
assert.Equal(t, "bar", (&StringFlag{Name: "foo", Value: "bar"}).GetValue())
3135+
}

0 commit comments

Comments
 (0)