Documentation ¶
Index ¶
- Variables
- func Exitf(code int, f string, args ...interface{}) error
- func Main(cmd Command)
- func WithCommandInfo(ctx context.Context, info CommandInfo) context.Context
- type Command
- type CommandFunc
- type CommandInfo
- type Commands
- type Container
- type DescriptionProvider
- type FlagDefiner
- type NameProvider
- type Runner
- type SynopsisProvider
Constants ¶
This section is empty.
Variables ¶
var DefaultRunner = Runner{ TermSignals: []os.Signal{ syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, }, }
DefaultRunner is an instance of Runner used by Main().
Functions ¶
func Exitf ¶
Exitf creates an error which reception cause Runner.Main() to exit with given code preceded by formatted message.
func WithCommandInfo ¶
func WithCommandInfo(ctx context.Context, info CommandInfo) context.Context
WithCommandInfo returns a new context with given command info added to the execution path.
WithCommandInfo is called internally during command chain execution. It might be called from third parties only for testing purposes.
Types ¶
type CommandFunc ¶
CommandFunc is an adapter to allow the use of ordinary functions as Commands.
type CommandInfo ¶
func ContextCommandsInfo ¶
func ContextCommandsInfo(ctx context.Context) []CommandInfo
ContextCommandsInfo returns commands execution path associated with context. Last element of the slice is the Command which Run() method is currently running.
Callers must not mutate returned slice.
type Commands ¶
Commands holds a mapping of sub command name to its implementation.
func (Commands) Description ¶
Description implements DescriptionProvider interface.
type Container ¶
type Container struct { Command Command // DoRun allows to override Command behaviour. DoRun func(context.Context, []string) error // DoName allows to override NameProvider behaviour. DoName func() string // DoSynopsis allows to override SynopsisProvider behaviour. DoSynopsis func() string // DoDescription allows to override DescriptionProvider behaviour. DoDescription func() string // DoDefineFlags allows to override FlagDefiner behaviour. DoDefineFlags func(*flag.FlagSet) }
Container is a Command wrapper which allows to modify behaviour of the Command it wraps.
func (*Container) DefineFlags ¶
DefineFlags implements FlagDefiner interface.
func (*Container) Description ¶
Description implements DescriptionProvider interface.
type DescriptionProvider ¶
type DescriptionProvider interface {
Description() string
}
type FlagDefiner ¶
type NameProvider ¶
type NameProvider interface {
Name() string
}
type Runner ¶
type Runner struct { // TermSignals specifies termination OS signals which must be used to // cancel context passed to Command's Run() method. TermSignals []os.Signal // ForceTerm specifies whether reception of same signal specified in // TermSignals this amount of times should result into os.Exit() call. ForceTerm int // DoParseFlags allows to override standard way of flags parsing. // It should return remaining arguments (same as flag.Args() does) or // error. DoParseFlags func(context.Context, *flag.FlagSet, []string) ([]string, error) // DoPrintFlags allows to override standard way of flags printing. // It should write all output into given io.Writer. DoPrintFlags func(context.Context, io.Writer, *flag.FlagSet) error }
Runner holds options for running commands.
type SynopsisProvider ¶
type SynopsisProvider interface {
Synopsis() string
}