Skip to content

Commit 85d7683

Browse files
authored
feat(unmarshal): parse time.Duration (#2521)
1 parent 5f55609 commit 85d7683

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/args/unmarshal.go

+9
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ var unmarshalFuncs = map[reflect.Type]UnmarshalFunc{
9090
RelativeTimeParseError: relativeErr,
9191
}
9292
},
93+
94+
reflect.TypeOf((*time.Duration)(nil)).Elem(): func(value string, dest interface{}) error {
95+
duration, err := time.ParseDuration(value)
96+
if err != nil {
97+
return fmt.Errorf("failed to parse duration: %w", err)
98+
}
99+
*(dest.(*time.Duration)) = duration
100+
return nil
101+
},
93102
}
94103

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

0 commit comments

Comments
 (0)