mirror of
https://github.com/rclone/rclone.git
synced 2025-08-17 09:01:33 +02:00
fs: Add string alternatives for setting options over the rc
Before this change options were read and set in native format. This means for example nanoseconds for durations or an integer for enumerated types, which isn't very convenient for humans. This change enables these types to be set with a string with the syntax as used in the command line instead, so `"10s"` rather than `10000000000` or `"DEBUG"` rather than `8` for log level.
This commit is contained in:
@ -196,6 +196,14 @@ func (d Duration) Type() string {
|
||||
return "Duration"
|
||||
}
|
||||
|
||||
// UnmarshalJSON makes sure the value can be parsed as a string or integer in JSON
|
||||
func (d *Duration) UnmarshalJSON(in []byte) error {
|
||||
return UnmarshalJSONFlag(in, d, func(i int64) error {
|
||||
*d = Duration(i)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Scan implements the fmt.Scanner interface
|
||||
func (d *Duration) Scan(s fmt.ScanState, ch rune) error {
|
||||
token, err := s.Token(true, nil)
|
||||
|
Reference in New Issue
Block a user