Skip to content
Merged
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
28 changes: 28 additions & 0 deletions flagset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"flag"
"fmt"
"os"
"reflect"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -462,6 +464,32 @@ func TestDefaultsViaTag(t *testing.T) {
`, buf.String())
}

func TestSimpleTypeDefaultsViaTag(t *testing.T) {
type Config struct {
Count int16 `default:"42"`
}

flagsfiller.RegisterSimpleType(func(s string, tag reflect.StructTag) (int16, error) {
i, err := strconv.ParseInt(s, 10, 16)
return int16(i), err
})

var config Config

filler := flagsfiller.New()

var flagset flag.FlagSet
err := filler.Fill(&flagset, &config)
require.NoError(t, err)

buf := grabUsage(flagset)

assert.Equal(t, `
-count value
(default 42)
`, buf.String())
}

func TestBadDefaultsViaTag(t *testing.T) {
type BadBoolConfig struct {
Enabled bool `default:"wrong"`
Expand Down
2 changes: 1 addition & 1 deletion simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v *simpleType[T]) String() string {
if v.val == nil {
return fmt.Sprint(nil)
}
return fmt.Sprint(v.val)
return fmt.Sprint(*v.val)
}

func (v *simpleType[T]) StrConverter(s string) (T, error) {
Expand Down