6 "github.com/pkg/errors"
9 // PositiveDurationOpt is an option type for time.Duration that uses a pointer.
10 // It behave similarly to DurationOpt but only allows positive duration values.
11 type PositiveDurationOpt struct {
15 // Set a new value on the option. Setting a negative duration value will cause
16 // an error to be returned.
17 func (d *PositiveDurationOpt) Set(s string) error {
18 err := d.DurationOpt.Set(s)
22 if *d.DurationOpt.value < 0 {
23 return errors.Errorf("duration cannot be negative")
28 // DurationOpt is an option type for time.Duration that uses a pointer. This
29 // allows us to get nil values outside, instead of defaulting to 0
30 type DurationOpt struct {
34 // NewDurationOpt creates a DurationOpt with the specified duration
35 func NewDurationOpt(value *time.Duration) *DurationOpt {
41 // Set a new value on the option
42 func (d *DurationOpt) Set(s string) error {
43 v, err := time.ParseDuration(s)
48 // Type returns the type of this option, which will be displayed in `--help` output
49 func (d *DurationOpt) Type() string {
53 // String returns a string repr of this option
54 func (d *DurationOpt) String() string {
56 return d.value.String()
61 // Value returns the time.Duration
62 func (d *DurationOpt) Value() *time.Duration {