github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/plugin/options.go (about)

     1  package plugin
     2  
     3  import (
     4  	"github.com/urfave/cli/v2"
     5  )
     6  
     7  // Options are used as part of a new plugin
     8  type Options struct {
     9  	Name     string
    10  	Flags    []cli.Flag
    11  	Commands []*cli.Command
    12  	Handlers []Handler
    13  	Init     func(*cli.Context) error
    14  }
    15  
    16  type Option func(o *Options)
    17  
    18  // WithFlag adds flags to a plugin
    19  func WithFlag(flag ...cli.Flag) Option {
    20  	return func(o *Options) {
    21  		o.Flags = append(o.Flags, flag...)
    22  	}
    23  }
    24  
    25  // WithCommand adds commands to a plugin
    26  func WithCommand(cmd ...*cli.Command) Option {
    27  	return func(o *Options) {
    28  		o.Commands = append(o.Commands, cmd...)
    29  	}
    30  }
    31  
    32  // WithHandler adds middleware handlers to
    33  func WithHandler(h ...Handler) Option {
    34  	return func(o *Options) {
    35  		o.Handlers = append(o.Handlers, h...)
    36  	}
    37  }
    38  
    39  // WithName defines the name of the plugin
    40  func WithName(n string) Option {
    41  	return func(o *Options) {
    42  		o.Name = n
    43  	}
    44  }
    45  
    46  // WithInit sets the init function
    47  func WithInit(fn func(*cli.Context) error) Option {
    48  	return func(o *Options) {
    49  		o.Init = fn
    50  	}
    51  }