cli

package
v0.0.0-...-51fcc54 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cli contains utilities to work with IO streams.

Index

Constants

This section is empty.

Variables

View Source
var DefaultIOStreams = IOStreams{
	In:     os.Stdin,
	Out:    os.Stdout,
	ErrOut: os.Stderr,
}

DefaultIOStreams provides the default streams for os.Stdin, os.Stdout and os.Stderr.

Functions

func Run

func Run(fn func() error)

Run runs fn and handles returned errors by exiting the program with a suitable exit code.

Types

type IOStreams

type IOStreams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
}

IOStreams is a holder for input and output streams. Commands should use this instead of directly relying on os.Stdin, os.Stdout and os.Stderr to make it possible to replace the streams in tests.

func NewTestIOStreams

func NewTestIOStreams() (streams IOStreams, in *bytes.Buffer, out *bytes.Buffer, errOut *bytes.Buffer)

NewTestIOStreams provides IOStreams that use a *bytes.Buffer. This can be used in tests to make assertions on command output as well as control the input stream. Returns IOStreams and *bytes.Buffer for in, out and errOut.

Jump to

Keyboard shortcuts

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