fs: make display of default values of --min-age/--max-age be off - Fixes #2121

This commit is contained in:
Nick Craig-Wood
2018-03-12 20:52:42 +00:00
parent 4e90ad04d5
commit 0c9dc006c5
3 changed files with 49 additions and 20 deletions

View File

@ -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"
}