Files
obitools4/pkg/obichunk/options.go

162 lines
2.9 KiB
Go
Raw Normal View History

2022-02-18 09:58:08 +01:00
package obichunk
import "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obioptions"
2022-02-18 09:58:08 +01:00
type __options__ struct {
statsOn []string
categories []string
navalue string
cacheOnDisk bool
batchCount int
batchSize int
parallelWorkers int
2022-02-24 12:14:52 +01:00
noSingleton bool
2022-02-18 09:58:08 +01:00
}
type Options struct {
pointer *__options__
}
type WithOption func(Options)
func MakeOptions(setters []WithOption) Options {
o := __options__{
statsOn: make([]string, 0, 100),
categories: make([]string, 0, 100),
navalue: "NA",
cacheOnDisk: false,
batchCount: 100,
batchSize: obioptions.CLIBatchSize(),
parallelWorkers: obioptions.CLIParallelWorkers(),
2022-02-24 12:14:52 +01:00
noSingleton: false,
2022-02-18 09:58:08 +01:00
}
opt := Options{&o}
for _, set := range setters {
set(opt)
}
return opt
}
func (opt Options) Categories() []string {
return opt.pointer.categories
}
func (opt Options) PopCategories() string {
if len(opt.pointer.categories) > 0 {
c := opt.pointer.categories[0]
opt.pointer.categories = opt.pointer.categories[1:]
return c
}
return ""
}
func (opt Options) StatsOn() []string {
return opt.pointer.statsOn
}
func (opt Options) NAValue() string {
return opt.pointer.navalue
}
func (opt Options) BatchCount() int {
return opt.pointer.batchCount
}
func (opt Options) BatchSize() int {
return opt.pointer.batchSize
}
func (opt Options) ParallelWorkers() int {
return opt.pointer.parallelWorkers
}
func (opt Options) SortOnDisk() bool {
return opt.pointer.cacheOnDisk
}
2022-02-24 12:14:52 +01:00
func (opt Options) NoSingleton() bool {
return opt.pointer.noSingleton
}
2022-02-18 09:58:08 +01:00
func OptionSortOnDisk() WithOption {
f := WithOption(func(opt Options) {
opt.pointer.cacheOnDisk = true
})
return f
}
func OptionSortOnMemory() WithOption {
f := WithOption(func(opt Options) {
opt.pointer.cacheOnDisk = false
})
return f
}
func OptionSubCategory(keys ...string) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.categories = append(opt.pointer.categories, keys...)
})
return f
}
func OptionNAValue(na string) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.navalue = na
})
return f
}
func OptionStatOn(keys ...string) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.statsOn = append(opt.pointer.categories, keys...)
})
return f
}
func OptionBatchCount(number int) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.batchCount = number
})
return f
}
func OptionsParallelWorkers(nworkers int) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.parallelWorkers = nworkers
})
return f
}
func OptionsBatchSize(size int) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.batchSize = size
})
return f
}
2022-02-24 12:14:52 +01:00
func OptionsNoSingleton() WithOption {
f := WithOption(func(opt Options) {
opt.pointer.noSingleton = true
})
return f
}
func OptionsWithSingleton() WithOption {
f := WithOption(func(opt Options) {
opt.pointer.noSingleton = false
})
return f
}