Documentation
¶
Index ¶
- func BuildRoot(ctx *AppContext) *cobra.Command
- func ConfigureRoot(root *cobra.Command, ctx *AppContext, postInit func(*viper.Viper) error)
- func Execute(root *cobra.Command, args ...string) (string, error)
- func ExecuteC(root *cobra.Command, args ...string) (*cobra.Command, string, error)
- func NewRoot(ctx *AppContext, p Palette) *cobra.Command
- func Register(factories ...CommandFactory)
- type AppContext
- func (ctx *AppContext) AvailableTargets() []string
- func (ctx *AppContext) Messenger() Messenger
- func (ctx *AppContext) RegisterTransformer(name string, t transform.Transformer)
- func (ctx *AppContext) SetMessenger(m Messenger)
- func (ctx *AppContext) Transformer(target string) (transform.Transformer, error)
- type CommandFactory
- type Logger
- type Messenger
- type Palette
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildRoot ¶
func BuildRoot(ctx *AppContext) *cobra.Command
BuildRoot builds a root command using the global palette and provided context.
func ConfigureRoot ¶
ConfigureRoot attaches common flags and a PersistentPreRunE to an existing root command to initialize the provided AppContext.Viper instance. If postInit is non-nil it will be invoked after the config has been read.
func NewRoot ¶
func NewRoot(ctx *AppContext, p Palette) *cobra.Command
NewRoot constructs the root command and composes the provided palette using the given AppContext. Config initialization is performed in PersistentPreRunE so construction is side-effect free and testable.
func Register ¶
func Register(factories ...CommandFactory)
Register registers command factories into the global palette.
Types ¶
type AppContext ¶
type AppContext struct {
Viper *viper.Viper
Logger Logger
UI Messenger
// contains filtered or unexported fields
}
AppContext carries shared dependencies for command factories.
func NewAppContext ¶
func NewAppContext(v *viper.Viper, l Logger) *AppContext
NewAppContext creates a default AppContext with provided logger and viper instance. Passing nil for the logger uses the standard library default logger.
func (*AppContext) AvailableTargets ¶ added in v0.5.0
func (ctx *AppContext) AvailableTargets() []string
AvailableTargets returns a list of registered transformer names.
func (*AppContext) Messenger ¶ added in v0.7.1
func (ctx *AppContext) Messenger() Messenger
Messenger returns the currently configured messenger.
func (*AppContext) RegisterTransformer ¶ added in v0.5.0
func (ctx *AppContext) RegisterTransformer(name string, t transform.Transformer)
RegisterTransformer adds a transformer to the context.
func (*AppContext) SetMessenger ¶ added in v0.7.1
func (ctx *AppContext) SetMessenger(m Messenger)
SetMessenger replaces the current messenger if a non-nil value is provided.
func (*AppContext) Transformer ¶ added in v0.5.0
func (ctx *AppContext) Transformer(target string) (transform.Transformer, error)
Transformer retrieves a transformer by name.
type CommandFactory ¶
type CommandFactory func(*AppContext) *cobra.Command
CommandFactory builds a cobra command using the provided AppContext.
func FromCommand ¶
func FromCommand(c *cobra.Command) CommandFactory
FromCommand wraps an existing *cobra.Command as a CommandFactory.
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger is a minimal logging interface used by AppContext.
func NewGoBasetoolsAdapter ¶
func NewGoBasetoolsAdapter() Logger
NewGoBasetoolsAdapter returns a Logger that routes to the go-basetools configured slog default logger. It is safe to call even before InitLogger; slog will use the standard library logger by default.
func NewReflectLoggerAdapter ¶
func NewReflectLoggerAdapter(l interface{}) Logger
NewReflectLoggerAdapter returns a Logger that will call Printf on the provided logger value (useful to adapt third-party loggers). If l is nil, the standard library logger is used.
func NewStdLoggerAdapter ¶
NewStdLoggerAdapter wraps the standard library logger as a Logger.
type Messenger ¶ added in v0.7.1
type Messenger interface {
Success(format string, args ...interface{})
Info(format string, args ...interface{})
Warn(format string, args ...interface{})
Error(format string, args ...interface{})
Debug(format string, args ...interface{})
}
Messenger centralizes user-facing output formatting.
type Palette ¶
type Palette []CommandFactory
Palette is an ordered collection of CommandFactory instances that can be composed into a root command.
var DefaultPalette Palette
Simple global palette registry for incremental migration.
func (Palette) Commands ¶
func (p Palette) Commands(ctx *AppContext) []*cobra.Command
Commands builds concrete *cobra.Command slice using the provided context.
func (*Palette) Register ¶
func (p *Palette) Register(factories ...CommandFactory)
Register adds factories to the palette.