Documentation
¶
Index ¶
- Variables
- func IsReaderTerminal(r io.Reader) bool
- func IsWriterTerminal(w io.Writer) bool
- func WithContext(ctx context.Context, p Printer) context.Context
- type Contextual
- type ContextualPrinter
- type InputOutput
- type OsInOut
- type Printer
- type TestOutputs
- type TestPrinter
- func (p TestPrinter) Outputs() TestOutputs
- func (p TestPrinter) Print(i ...any)
- func (p TestPrinter) PrintErr(i ...any)
- func (p TestPrinter) PrintErrf(format string, i ...any)
- func (p TestPrinter) PrintErrln(i ...any)
- func (p TestPrinter) Printf(format string, i ...any)
- func (p TestPrinter) Println(i ...any)
Constants ¶
This section is empty.
Variables ¶
var OsPrinter = stdPrinter{OsInOut{}} //nolint:gochecknoglobals
OsPrinter is the default printer for the CLI. It uses the standard input, output, and error streams.
Functions ¶
func IsReaderTerminal ¶
IsReaderTerminal returns true if the given reader is a real terminal.
func IsWriterTerminal ¶
IsWriterTerminal returns true if the given writer is a real terminal.
Types ¶
type Contextual ¶ added in v0.2.0
Contextual is an interface for types that can provide a context.Context.
type ContextualPrinter ¶ added in v0.2.0
type ContextualPrinter struct { Contextual Printer }
ContextualPrinter is a type that embeds a Contextual and a Printer.
type InputOutput ¶
type InputOutput interface { InOrStdin() io.Reader OutOrStdout() io.Writer ErrOrStderr() io.Writer }
InputOutput is an interface for types that can provide input and output and error streams. It is compatible with Cobra functions, so that the cobra.Command can be passed an InputOutput implementation.
type OsInOut ¶
type OsInOut struct{}
OsInOut is an InputOutput implementation that uses the standard input, output, and error streams.
func (OsInOut) ErrOrStderr ¶
func (OsInOut) OutOrStdout ¶
type Printer ¶
type Printer interface { Print(i ...any) Println(i ...any) Printf(format string, i ...any) PrintErr(i ...any) PrintErrln(i ...any) PrintErrf(format string, i ...any) InputOutput }
func PrinterFrom ¶
PrinterFrom returns the Printer from the context, or the default printer if none is set. The default printer is OsPrinter.
type TestOutputs ¶
TestOutputs is a struct that contains the output and error buffers.
func (TestOutputs) ErrOrStderr ¶
func (t TestOutputs) ErrOrStderr() io.Writer
ErrOrStderr returns the error stream.
func (TestOutputs) OutOrStdout ¶
func (t TestOutputs) OutOrStdout() io.Writer
OutOrStdout returns the output stream.
type TestPrinter ¶
type TestPrinter struct {
// contains filtered or unexported fields
}
TestPrinter is an InputOutput implementation that uses a buffer for input.
func NewTestPrinter ¶
func NewTestPrinter() TestPrinter
NewTestPrinter returns a TestPrinter with a buffer for input.
func NewTestPrinterWithAnswers ¶
func NewTestPrinterWithAnswers(answers []string) TestPrinter
NewTestPrinterWithAnswers returns a TestPrinter with the given answers as input.
func NewTestPrinterWithInput ¶
func NewTestPrinterWithInput(input io.Reader) TestPrinter
NewTestPrinterWithInput returns a TestPrinter with the given input.
func (TestPrinter) Outputs ¶
func (p TestPrinter) Outputs() TestOutputs
func (TestPrinter) PrintErrln ¶
func (p TestPrinter) PrintErrln(i ...any)