output

package
v0.40.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package output is a generated GoMock package.

Index

Constants

View Source
const (
	FormatJson    = "json"
	FormatTable   = "table"
	DefaultFormat = FormatTable
)
View Source
const (
	ProgressFailed    = "Failed"
	ProgressCompleted = "Completed"
)
View Source
const (
	TableColumnMinWidth = 10
	TableTabSize        = 4
	TablePadSize        = 2
	TablePadCharacter   = ' '
	TableFlags          = 0
)

Based on https://golang.org/pkg/text/tabwriter/

Variables

View Source
var ProgressDefaultSpinner = []string{".  ", ".. ", "..."}

Functions

func CompleteStep

func CompleteStep(step Step)

CompleteStep ends execution of a step

func FormatResourceForDisplay

func FormatResourceForDisplay(id ucpresources.ID) string

FormatResourceForDisplay returns a display string for the resource type and name.

func FormatResourceForProgressDisplay

func FormatResourceForProgressDisplay(id ucpresources.ID) string

FormatResourceForProgressDisplay returns a display string for a progress spinner, resource type, and name.

func FormatResourceNameForDisplay

func FormatResourceNameForDisplay(id ucpresources.ID) string

FormatResourceNameForDisplay returns a display string for the resource name.

func FormatResourceTypeForDisplay

func FormatResourceTypeForDisplay(id ucpresources.ID) string

FormatResourceTypeForDisplay returns a display string for the resource type.

func LogInfo

func LogInfo(format string, v ...any)

LogInfo logs a message that is displayed to the user by default.

func ShowResource

func ShowResource(id ucpresources.ID) bool

ShowResource returns true if the resource should be displayed to the user.

func SupportedFormats

func SupportedFormats() []string

SupportedFormats returns a slice of strings containing the supported formats for a request.

func Write

func Write(format string, obj any, writer io.Writer, options FormatterOptions) error

Write takes in a format string, an object, a writer and formatter options and attempts to format the object according to the format string and write it to the writer. If an error occurs during formatting or writing, an error is returned.

Types

type Column

type Column struct {
	Heading     string
	JSONPath    string
	Transformer ColumnTransformer
}

type ColumnTransformer added in v0.28.0

type ColumnTransformer interface {
	Transform(input string) string
}

ColumnTransformer is an interface for transforming a column value for display.

NOTE: this is an interface so that we can easily compare data in tests.

type FormattedOutput

type FormattedOutput struct {
	Format  string
	Obj     any
	Options FormatterOptions
}

type Formatter

type Formatter interface {
	Format(obj any, writer io.Writer, options FormatterOptions) error
}

func NewFormatter

func NewFormatter(format string) (Formatter, error)

NewFormatter takes in a string and returns a Formatter interface and an error if the format is not supported.

type FormatterOptions

type FormatterOptions struct {
	// Columns used for table formatting
	Columns []Column
}

type Interface

type Interface interface {
	// LogInfo logs a message that is displayed to the user by default.
	LogInfo(format string, v ...any)

	// Write
	WriteFormatted(format string, obj any, options FormatterOptions) error
}

Interface is a mockable interface for writing cli output

type JSONFormatter

type JSONFormatter struct {
}

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(obj any, writer io.Writer, options FormatterOptions) error

Format takes in an object, a writer and an options object and marshals the object into JSON, writing it to the writer, and returns an error if any of the operations fail.

type LogOutput

type LogOutput struct {
	Format string
	Params []any
}

type MockInterface

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

MockInterface is a mock of Interface interface.

func NewMockInterface

func NewMockInterface(ctrl *gomock.Controller) *MockInterface

NewMockInterface creates a new mock instance.

func (*MockInterface) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockInterface) Write

func (m *MockInterface) Write(arg0 string, arg1 any, arg2 FormatterOptions) error

Write mocks base method.

type MockInterfaceMockRecorder

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

MockInterfaceMockRecorder is the mock recorder for MockInterface.

func (*MockInterfaceMockRecorder) Write

func (mr *MockInterfaceMockRecorder) Write(arg0, arg1, arg2 any) *gomock.Call

Write indicates an expected call of Write.

type MockOutput

type MockOutput struct {
	Writes []any
}

func (*MockOutput) LogInfo

func (o *MockOutput) LogInfo(format string, v ...any)

LogInfo takes in a format string and a variable number of parameters and appends them to the Writes slice.

func (*MockOutput) WriteFormatted

func (o *MockOutput) WriteFormatted(format string, obj any, options FormatterOptions) error

WriteFormatted takes in a format string, an object of any type, and a FormatterOptions object, and appends them to the Writes slice, returning no error.

type OutputWriter

type OutputWriter struct {
	Writer io.Writer
}

func (*OutputWriter) LogInfo

func (o *OutputWriter) LogInfo(format string, v ...any)

LogInfo takes in a format string and a variable number of arguments and prints the formatted string to the Writer.

func (*OutputWriter) WriteFormatted

func (o *OutputWriter) WriteFormatted(format string, obj any, options FormatterOptions) error

WriteFormatted takes in a format string, an object of any type, and a FormatterOptions object, and calls the Write function with the given parameters, writing the output to the Writer field of the OutputWriter object.

type Step

type Step struct {
}

Step represents a logical step that's being executed.

func BeginStep

func BeginStep(format string, v ...any) Step

BeginStep starts execution of a step

type Stream

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

func (*Stream) Print

func (s *Stream) Print(text string)

Print takes a string and prints it to the output stream with a prefix of the stream's name in a secondary color.

func (*Stream) Writer

func (s *Stream) Writer() io.WriteCloser

Writer() returns an io.WriteCloser which is a StreamWriter struct that contains a pointer to the Stream struct.

type StreamGroup

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

StreamGroup represents a group of related output streams of different colors. All functionality of StreamGroup can be used concurrently.

func NewStreamGroup

func NewStreamGroup(out io.Writer) *StreamGroup

NewStreamGroup creates a new StreamGroup object with an output writer and a mutex, and returns a pointer to the newly created StreamGroup.

func (*StreamGroup) NewStream

func (sg *StreamGroup) NewStream(name string) *Stream

NewStream() creates a new Stream object with a given name, assigns it a primary and secondary color, and returns it.

type StreamWriter

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

StreamWriter implements io.Writer for a Stream.

func (*StreamWriter) Close

func (w *StreamWriter) Close() error

Close flushes the stream and returns an error if the flush fails.

func (*StreamWriter) Write

func (w *StreamWriter) Write(p []byte) (int, error)

Write buffers all bytes written to it and outputs complete lines to the colorized stream as it sees them, and returns an error if it fails to flush the buffer.

type TableFormatter

type TableFormatter struct {
}

func (*TableFormatter) Format

func (f *TableFormatter) Format(obj any, writer io.Writer, options FormatterOptions) error

Format() takes in an object, a writer and formatting options and writes a table to the writer using the formatting options. If no columns are defined, an error is returned.

Jump to

Keyboard shortcuts

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