cronrange icon indicating copy to clipboard operation
cronrange copied to clipboard

Added parser options: DefaultDuration

Open aubelsb2 opened this issue 4 years ago • 2 comments

I've added a defautl duration as required for my usecase.

It changes the signature to the Parse function but by using vargs it shouldn't impact any existing usage. I have extended the test cases to match too.

A futher extension I would consider for my use-case is: DisableCustomDuration to force the default duration. (Or perhaps it would be "ForceDuration?")

I haven't found a "great" way of doing opt args for options. This is typically how I do it. I have also seen people use it as an internal struct modifier ie:

type Opts struct {
 defautlDuration *time.Duration
}

type ParserOpt interface {
  Apply(o *Opts) error
}

type DefaultDuration time.Duration

func (dd DefaultDuration) Apply(o *Opts) error {
  var t time.Duration = time.Duration(dd)
  o.defaultDuration = &t
  return nil 
}

...
for _ opt := range opts { opt.apply(&opts) }
...

aubelsb2 avatar Aug 09 '21 02:08 aubelsb2

Fixed other deepsource issues in other PR. https://github.com/1set/cronrange/pull/17 if both merged there should be no issue

aubelsb2 avatar Aug 12 '21 00:08 aubelsb2

Merge conflict resolved.

aubelsb2 avatar Feb 16 '22 22:02 aubelsb2