File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 55 "flag"
66 "fmt"
77 "os"
8+ "reflect"
9+ "strconv"
810 "testing"
911 "time"
1012
@@ -462,6 +464,32 @@ func TestDefaultsViaTag(t *testing.T) {
462464` , buf .String ())
463465}
464466
467+ func TestSimpleTypeDefaultsViaTag (t * testing.T ) {
468+ type Config struct {
469+ Count int16 `default:"42"`
470+ }
471+
472+ flagsfiller .RegisterSimpleType (func (s string , tag reflect.StructTag ) (int16 , error ) {
473+ i , err := strconv .ParseInt (s , 10 , 16 )
474+ return int16 (i ), err
475+ })
476+
477+ var config Config
478+
479+ filler := flagsfiller .New ()
480+
481+ var flagset flag.FlagSet
482+ err := filler .Fill (& flagset , & config )
483+ require .NoError (t , err )
484+
485+ buf := grabUsage (flagset )
486+
487+ assert .Equal (t , `
488+ -count value
489+ (default 42)
490+ ` , buf .String ())
491+ }
492+
465493func TestBadDefaultsViaTag (t * testing.T ) {
466494 type BadBoolConfig struct {
467495 Enabled bool `default:"wrong"`
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ func (v *simpleType[T]) String() string {
3232 if v .val == nil {
3333 return fmt .Sprint (nil )
3434 }
35- return fmt .Sprint (v .val )
35+ return fmt .Sprint (* v .val )
3636}
3737
3838func (v * simpleType [T ]) StrConverter (s string ) (T , error ) {
You can’t perform that action at this time.
0 commit comments