commandrunner

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 7 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.

Jump to

Keyboard shortcuts

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