-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
51 lines (43 loc) · 992 Bytes
/
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
package plugin
import (
"github.com/micro/cli/v2"
)
// Options are used as part of a new plugin
type Options struct {
Name string
Flags []cli.Flag
Commands []*cli.Command
Handlers []Handler
Init func(*cli.Context) error
}
type Option func(o *Options)
// WithFlag adds flags to a plugin
func WithFlag(flag ...cli.Flag) Option {
return func(o *Options) {
o.Flags = append(o.Flags, flag...)
}
}
// WithCommand adds commands to a plugin
func WithCommand(cmd ...*cli.Command) Option {
return func(o *Options) {
o.Commands = append(o.Commands, cmd...)
}
}
// WithHandler adds middleware handlers to
func WithHandler(h ...Handler) Option {
return func(o *Options) {
o.Handlers = append(o.Handlers, h...)
}
}
// WithName defines the name of the plugin
func WithName(n string) Option {
return func(o *Options) {
o.Name = n
}
}
// WithInit sets the init function
func WithInit(fn func(*cli.Context) error) Option {
return func(o *Options) {
o.Init = fn
}
}