Documentation
¶
Overview ¶
Package commandrunner provides helpers for executing Cobra commands while capturing their output and displaying it to the console.
Index ¶
- func MergeCommandError(base error, res CommandResult) error
- type CobraCommandRunner
- type CommandResult
- type CommandRunner
- type MockCommandRunner
- type MockCommandRunner_Expecter
- type MockCommandRunner_Run_Call
- func (_c *MockCommandRunner_Run_Call) Return(commandResult CommandResult, err error) *MockCommandRunner_Run_Call
- func (_c *MockCommandRunner_Run_Call) Run(run func(ctx context.Context, cmd *cobra.Command, args []string)) *MockCommandRunner_Run_Call
- func (_c *MockCommandRunner_Run_Call) RunAndReturn(...) *MockCommandRunner_Run_Call
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeCommandError ¶
func MergeCommandError(base error, res CommandResult) error
MergeCommandError enriches a base error with captured stdout/stderr when available.
Types ¶
type CobraCommandRunner ¶
type CobraCommandRunner struct {
// contains filtered or unexported fields
}
CobraCommandRunner executes any Cobra command with console output. This runner displays command output to stdout/stderr in real-time while also capturing it for the result.
func NewCobraCommandRunner ¶
func NewCobraCommandRunner(stdout, stderr io.Writer) *CobraCommandRunner
NewCobraCommandRunner creates a command runner that works with any Cobra command. It displays output to the console in real-time (like running the binary directly) while also capturing output for programmatic use.
func (*CobraCommandRunner) Run ¶
func (r *CobraCommandRunner) Run( ctx context.Context, cmd *cobra.Command, args []string, ) (CommandResult, error)
Run executes a Cobra command and displays output in real-time to console.
type CommandResult ¶
CommandResult captures the stdout and stderr collected during a Cobra command execution.
type CommandRunner ¶
type CommandRunner interface {
Run(ctx context.Context, cmd *cobra.Command, args []string) (CommandResult, error)
}
CommandRunner executes Cobra commands while capturing their output.
type MockCommandRunner ¶ added in v1.14.0
MockCommandRunner is an autogenerated mock type for the CommandRunner type
func NewMockCommandRunner ¶ added in v1.14.0
func NewMockCommandRunner(t interface {
mock.TestingT
Cleanup(func())
}) *MockCommandRunner
NewMockCommandRunner creates a new instance of MockCommandRunner. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockCommandRunner) EXPECT ¶ added in v1.14.0
func (_m *MockCommandRunner) EXPECT() *MockCommandRunner_Expecter
func (*MockCommandRunner) Run ¶ added in v1.14.0
func (_mock *MockCommandRunner) Run(ctx context.Context, cmd *cobra.Command, args []string) (CommandResult, error)
Run provides a mock function for the type MockCommandRunner
type MockCommandRunner_Expecter ¶ added in v1.14.0
type MockCommandRunner_Expecter struct {
// contains filtered or unexported fields
}
func (*MockCommandRunner_Expecter) Run ¶ added in v1.14.0
func (_e *MockCommandRunner_Expecter) Run(ctx interface{}, cmd interface{}, args interface{}) *MockCommandRunner_Run_Call
Run is a helper method to define mock.On call
- ctx context.Context
- cmd *cobra.Command
- args []string
type MockCommandRunner_Run_Call ¶ added in v1.14.0
MockCommandRunner_Run_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Run'
func (*MockCommandRunner_Run_Call) Return ¶ added in v1.14.0
func (_c *MockCommandRunner_Run_Call) Return(commandResult CommandResult, err error) *MockCommandRunner_Run_Call
func (*MockCommandRunner_Run_Call) Run ¶ added in v1.14.0
func (_c *MockCommandRunner_Run_Call) Run(run func(ctx context.Context, cmd *cobra.Command, args []string)) *MockCommandRunner_Run_Call
func (*MockCommandRunner_Run_Call) RunAndReturn ¶ added in v1.14.0
func (_c *MockCommandRunner_Run_Call) RunAndReturn(run func(ctx context.Context, cmd *cobra.Command, args []string) (CommandResult, error)) *MockCommandRunner_Run_Call