-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
66 lines (53 loc) · 1.4 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package panylcli
import (
"github.com/RangelReale/panyl"
"github.com/spf13/pflag"
)
type options struct {
globalFlags FlagsProvider
presetFlags FlagsProvider
logFlags FlagsProvider
pluginOptions []PluginOption
processorProvider ProcessorProviderFunc
resultProvider ResultProviderFunc
}
type Option func(*options)
type FlagsProvider func(flags *pflag.FlagSet)
func WithDeclareGlobalFlags(f FlagsProvider) Option {
return func(o *options) {
o.globalFlags = f
}
}
func WithDeclarePresetFlags(f FlagsProvider) Option {
return func(o *options) {
o.presetFlags = f
}
}
func WithDeclareLogFlags(f FlagsProvider) Option {
return func(o *options) {
o.logFlags = f
}
}
type PluginOption struct {
Name string
Enabled bool
Preset bool
PresetEnabled bool
}
func WithPluginOptions(pluginOptions []PluginOption) Option {
return func(o *options) {
o.pluginOptions = append(o.pluginOptions, pluginOptions...)
}
}
type ProcessorProviderFunc func(preset string, pluginsEnabled []string, flags *pflag.FlagSet) (*panyl.Processor, []panyl.JobOption, error)
func WithProcessorProvider(f ProcessorProviderFunc) Option {
return func(o *options) {
o.processorProvider = f
}
}
type ResultProviderFunc func(flags *pflag.FlagSet) (panyl.ProcessResult, error)
func WithResultProvider(f ResultProviderFunc) Option {
return func(o *options) {
o.resultProvider = f
}
}