Skip to content

Commit 8b90883

Browse files
authored
feat(args): handle scw.Duration unmarshal as flat field (#3469)
1 parent b09ffbd commit 8b90883

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/args/unmarshal.go

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ var unmarshalFuncs = map[reflect.Type]UnmarshalFunc{
115115
*(dest.(*[]byte)) = []byte(value)
116116
return nil
117117
},
118+
reflect.TypeOf((*scw.Duration)(nil)).Elem(): func(value string, dest interface{}) error {
119+
duration, err := time.ParseDuration(value)
120+
if err != nil {
121+
return fmt.Errorf("failed to parse duration: %w", err)
122+
}
123+
*(dest.(*scw.Duration)) = *scw.NewDurationFromTimeDuration(duration)
124+
return nil
125+
},
118126
}
119127

120128
// UnmarshalStruct parses args like ["arg1=1", "arg2=2"] to a Go structure using reflection.

0 commit comments

Comments
 (0)