Documentation
¶
Overview ¶
Package cmd implements the CLI commands using Cobra.
Global variables are used for flag binding (a Cobra convention), but runtime state is passed through CommandContext via Cobra's context mechanism. This enables isolated testing and cleaner dependency injection.
Index ¶
- func Execute() error
- func ExitCode(executionError error) int
- func IsQuietIntent() bool
- func ResetQuietIntentForTests()
- func SetQuietIntent(v bool)
- func SetVersionInfo(v, c, d string)
- func WithCommandContext(ctx context.Context, cmdCtx *CommandContext) context.Context
- type CommandContext
- type CommandFlags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute() error
Execute adds all child commands to the root command and sets flags appropriately.
func IsQuietIntent ¶ added in v0.7.0
func IsQuietIntent() bool
IsQuietIntent reports whether quiet mode was requested via CLI flags.
func ResetQuietIntentForTests ¶ added in v0.7.0
func ResetQuietIntentForTests()
ResetQuietIntentForTests resets the quiet-intent flag for test isolation.
func SetQuietIntent ¶ added in v0.7.0
func SetQuietIntent(v bool)
SetQuietIntent records that quiet mode was requested.
func SetVersionInfo ¶
func SetVersionInfo(v, c, d string)
SetVersionInfo sets version information from main
func WithCommandContext ¶ added in v0.6.0
func WithCommandContext(ctx context.Context, cmdCtx *CommandContext) context.Context
WithCommandContext returns a new context with the CommandContext stored in it.
Types ¶
type CommandContext ¶ added in v0.6.0
type CommandContext struct {
// Runtime state (set during PersistentPreRunE)
Config *config.Config
Manager *container.Manager
// Flags - these are populated from the global flag variables after parsing.
// While Cobra requires global variables for flag binding, we copy values
// here for cleaner access and to enable test isolation.
Flags CommandFlags
}
CommandContext holds all state for command execution.
Usage in commands:
RunE: func(cmd *cobra.Command, args []string) error {
cmdCtx := GetCommandContext(cmd.Context())
return cmdCtx.Manager.SomeMethod()
}
This replaces global variables to enable: - Concurrent command testing - Isolated unit tests - Clean test state - Dependency injection
func GetCommandContext ¶ added in v0.6.0
func GetCommandContext(ctx context.Context) *CommandContext
GetCommandContext retrieves the CommandContext from a context. Returns nil if no CommandContext is stored.
func NewCommandContext ¶ added in v0.6.0
func NewCommandContext() *CommandContext
NewCommandContext creates a fresh CommandContext for testing or execution.