commandrunner

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package commandrunner provides helpers for executing Cobra commands while capturing their output and displaying it to the console.

Index

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

type CommandResult struct {
	Stdout string
	Stderr string
}

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

type MockCommandRunner struct {
	mock.Mock
}

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 (*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

type MockCommandRunner_Run_Call struct {
	*mock.Call
}

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 (*MockCommandRunner_Run_Call) Run added in v1.14.0

func (*MockCommandRunner_Run_Call) RunAndReturn added in v1.14.0

Jump to

Keyboard shortcuts

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