package options // Index option constants const ( RepoWindowStart = iota ) // IndexMakeSettings mkidx option settings type IndexMakeSettings struct { Events chan<- interface{} Quiet bool Progress bool } // IndexListSettings ls option settings type IndexListSettings struct { Meta string } // IndexMakeOption make options type type IndexMakeOption func(*IndexMakeSettings) error // IndexListOption ls options type type IndexListOption func(*IndexListSettings) error // IndexMakeOptions make options function func IndexMakeOptions(opts ...IndexMakeOption) (*IndexMakeSettings, error) { options := &IndexMakeSettings{ Events: nil, Quiet: false, Progress: false, } for _, opt := range opts { err := opt(options) if err != nil { return nil, err } } return options, nil } type indexMakeOpts struct{} // IndexMake options var IndexMake indexMakeOpts // Events specifies channel which will be used to report events about ongoing // Make operation. // // Note that if this channel blocks it may slowdown the make func (indexMakeOpts) Events(sink chan<- interface{}) IndexMakeOption { return func(settings *IndexMakeSettings) error { settings.Events = sink return nil } } // Quiet reduces event output func (indexMakeOpts) Quiet(quiet bool) IndexMakeOption { return func(settings *IndexMakeSettings) error { settings.Quiet = quiet return nil } } // Progress tells make whether to enable progress events func (indexMakeOpts) Progress(enable bool) IndexMakeOption { return func(settings *IndexMakeSettings) error { settings.Progress = enable return nil } } // IndexListOptions ls options function func IndexListOptions(opts ...IndexListOption) (*IndexListSettings, error) { options := &IndexListSettings{ Meta: "", } for _, opt := range opts { err := opt(options) if err != nil { return nil, err } } return options, nil }