cli_runner

package
v0.0.0-...-8b9a2a1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const StdoutBufferSize = 40 * 1024

The buffer size used to read stdout/stderr output from subprocesses, in bytes. Effectively this determines the maximum line length that can be handled in one go. Lines that are longer will be broken up.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIRunner

type CLIRunner struct {
}

CLIRunner is a wrapper around exec.CommandContext() to allow mocking.

func NewCLIRunner

func NewCLIRunner() *CLIRunner

func (*CLIRunner) CommandContext

func (cli *CLIRunner) CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd

func (*CLIRunner) RunWithTextOutput

func (cli *CLIRunner) RunWithTextOutput(
	ctx context.Context,
	logger zerolog.Logger,
	execCmd *exec.Cmd,
	logChunker LogChunker,
	lineChannel chan<- string,
) error

RunWithTextOutput runs a command and sends its output line-by-line to the lineChannel. Stdout and stderr are combined. Before returning. RunWithTextOutput() waits for the subprocess, to ensure it doesn't become defunct.

Note that all output read from the command is logged via `logChunker` as well, so the receiving end of the `lineChannel` does not have to do this.

type LogChunker

type LogChunker interface {
	// Flush sends any buffered logs to the listener.
	Flush(ctx context.Context) error
	// Append log lines to the buffer, sending to the listener when the buffer gets too large.
	Append(ctx context.Context, logLines ...string) error
}

Jump to

Keyboard shortcuts

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