cobramodules

package module
v0.0.0-...-e1f7bf0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

cobramodules

The cobramodules library provides a basic module system to support running multiple subsystems under a single Cobra command.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindModuleFlags

func BindModuleFlags(modules []Module, c *cobra.Command)

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

func RunModules(ctx context.Context, modules []Module) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL