Documentation
¶
Overview ¶
Package iostreams provides standard I/O stream abstractions for CLI commands.
Index ¶
- type IOStreams
- func (s IOStreams) Debug(msg string, args ...any)
- func (s IOStreams) ErrOut() io.Writer
- func (s IOStreams) Error(msg string, args ...any)
- func (s IOStreams) In() io.Reader
- func (s IOStreams) Info(msg string, args ...any)
- func (s IOStreams) LogLevel() *slog.LevelVar
- func (s IOStreams) Logger() *slog.Logger
- func (s IOStreams) Out() io.Writer
- func (s IOStreams) Warn(msg string, args ...any)
- func (s IOStreams) WithLogger(l *slog.Logger, level *slog.LevelVar) IOStreams
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 ¶
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 ¶
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 ¶
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 ¶
ErrOut returns the stderr writer. Returns io.Discard if no writer was configured.
func (IOStreams) Error ¶
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) Info ¶
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 ¶
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 ¶
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 ¶
Out returns the stdout writer. Returns io.Discard if no writer was configured.
func (IOStreams) Warn ¶
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 ¶
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.