Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindModuleFlags ¶
BindModuleFlags iterates over the given modules and calls Module.BindFlags.
func NewModuleRunner ¶
func NewModuleRunner(ctx context.Context, modules []Module) func(c *cobra.Command, args []string) error
NewModuleRunner returns a func that matches the signature of the cobra.Command RunE function. When executed, that returned func will start all the given modules.
func RunModules ¶
RunModules starts all the given modules in their own goroutine. Each module is expected to run until either an unrecoverable error occurs or the given context.Context is cancelled. Any errors returned by the modules are aggregated and returned as a together as a multierr.
Types ¶
type Module ¶
type Module interface { // BindFlags gives modules the opportunity to add module-specific command-line flags. Due to the way that binding // works with pointers, it's important to implement the Module interface with pointer receivers to ensure that pflag // binds to the correct instances. If you see that argument values are not being set correctly, that's a good sign // that the module instance is being passed by value somewhere. BindFlags(flagSet *pflag.FlagSet) // Start launches the module and is expected to block until either an unrecoverable error occurs or the given // context.Context is cancelled. Cleaning up and returning after the context.Context is cancelled is important // because it is expected that the module runner will wait for all modules to return before it can return. Start(ctx context.Context) error }
Module defines the interface used to segregate a command's subsystems. Each module is started in its own goroutine and is expected to run until either an unrecoverable error occurs or the given context.Context is cancelled.