iostreams

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package iostreams provides standard I/O stream abstractions for CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IOStreams

type IOStreams struct {
	// contains filtered or unexported fields
}

IOStreams provides standard input and output streams.

func New

func New(in io.Reader, out, errOut io.Writer) IOStreams

New builds an IOStreams over caller-supplied streams, synchronizing Out/ErrOut. nil out/errOut are stored as nil; Out() and ErrOut() return io.Discard for nil fields so direct writes are always safe. If the same writer is passed for both out and errOut, the two locks are independent; callers combining sinks must pre-synchronize the underlying writer.

func NewTestIOStreams

func NewTestIOStreams() (IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

NewTestIOStreams returns a valid IOStreams for testing with bytes.Buffer. It returns the IOStreams and separate buffers for In, Out, and ErrOut for inspection.

func (IOStreams) Debug

func (s IOStreams) Debug(msg string, args ...any)

Debug writes a debug-level diagnostic via the configured logger. It is a no-op when no logger has been set (see WithLogger).

func (IOStreams) ErrOut

func (s IOStreams) ErrOut() io.Writer

ErrOut returns the stderr writer. Returns io.Discard if no writer was configured.

func (IOStreams) Error

func (s IOStreams) Error(msg string, args ...any)

Error writes an error-level diagnostic via the configured logger. It is a no-op when no logger has been set (see WithLogger).

func (IOStreams) In

func (s IOStreams) In() io.Reader

In returns the stdin reader.

func (IOStreams) Info

func (s IOStreams) Info(msg string, args ...any)

Info writes an info-level diagnostic via the configured logger. It is a no-op when no logger has been set (see WithLogger).

func (IOStreams) LogLevel

func (s IOStreams) LogLevel() *slog.LevelVar

LogLevel returns the level control for a logger created by logger.Bind, or nil for a caller-supplied logger (whose level is not ours to change) or none.

func (IOStreams) Logger

func (s IOStreams) Logger() *slog.Logger

Logger returns the logger attached via WithLogger, or nil when none is set. Library entrypoints use this to honor a caller-supplied logger instead of binding their own (see logger.Bind).

func (IOStreams) Out

func (s IOStreams) Out() io.Writer

Out returns the stdout writer. Returns io.Discard if no writer was configured.

func (IOStreams) Warn

func (s IOStreams) Warn(msg string, args ...any)

Warn writes a warning-level diagnostic via the configured logger. It is a no-op when no logger has been set (see WithLogger).

func (IOStreams) WithLogger

func (s IOStreams) WithLogger(l *slog.Logger, level *slog.LevelVar) IOStreams

WithLogger returns a copy of s whose Debug/Info/Warn/Error methods delegate to l. level is the LevelVar controlling l, which lets logger.Bind re-level it in place; pass nil for a caller-supplied logger whose level is not ours to change.

Jump to

Keyboard shortcuts

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