cli

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cli contains utilities to work with IO streams and to improve CLI output, such as a custom log handler and a table writer.

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

This section is empty.

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() (IOStreams, *bytes.Buffer, *bytes.Buffer, *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.

type TableWriter

type TableWriter interface {
	// Append appends a row to the table.
	Append(row ...string)

	// SetHeader sets the table's header keys.
	SetHeader(keys ...string)

	// SetTablePadding sets the table's padding character(s).
	SetTablePadding(padding string)

	// Render renders the table.
	Render()
}

A TableWriter can create formatted tables.

func NewTableWriter

func NewTableWriter(w io.Writer) TableWriter

NewTableWriter creates a new TableWriter which writes the table to w upon calling Render().

Jump to

Keyboard shortcuts

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