mirror of
https://github.com/rclone/rclone.git
synced 2025-08-14 15:58:26 +02:00
fs: make display of default values of --min-age/--max-age be off - Fixes #2121
This commit is contained in:
@ -9,11 +9,22 @@ import (
|
||||
// Duration is a time.Duration with some more parsing options
|
||||
type Duration time.Duration
|
||||
|
||||
// DurationOff is the default value for flags which can be turned off
|
||||
const DurationOff = Duration((1 << 63) - 1)
|
||||
|
||||
// Turn Duration into a string
|
||||
func (d Duration) String() string {
|
||||
if d == DurationOff {
|
||||
return "off"
|
||||
}
|
||||
return time.Duration(d).String()
|
||||
}
|
||||
|
||||
// IsSet returns if the duration is != DurationOff
|
||||
func (d Duration) IsSet() bool {
|
||||
return d != DurationOff
|
||||
}
|
||||
|
||||
// We use time conventions
|
||||
var ageSuffixes = []struct {
|
||||
Suffix string
|
||||
@ -36,6 +47,10 @@ var ageSuffixes = []struct {
|
||||
func ParseDuration(age string) (time.Duration, error) {
|
||||
var period float64
|
||||
|
||||
if age == "off" {
|
||||
return time.Duration(DurationOff), nil
|
||||
}
|
||||
|
||||
for _, ageSuffix := range ageSuffixes {
|
||||
if strings.HasSuffix(age, ageSuffix.Suffix) {
|
||||
numberString := age[:len(age)-len(ageSuffix.Suffix)]
|
||||
@ -64,5 +79,5 @@ func (d *Duration) Set(s string) error {
|
||||
|
||||
// Type of the value
|
||||
func (d Duration) Type() string {
|
||||
return "time.Duration"
|
||||
return "duration"
|
||||
}
|
||||
|
Reference in New Issue
Block a user