Documentation ¶
Overview ¶
Package output provides functionality to write output in different formats.
Index ¶
- Constants
- Variables
- func Configv1ChangelogMessage(change *models.ResourceChange) string
- func Deprecated(cmd *cobra.Command, alternatives ...string)
- type ColorPrinter
- type FileOperation
- type FileOps
- type Flags
- func (f *Flags) AddFlags(cmd *cobra.Command)
- func (f Flags) Close(w io.Writer) error
- func (f Flags) NewWriterManager(w io.Writer) (*WriterManager, error)
- func (f *Flags) Validate() error
- func (f *Flags) WithOutputOptions(opts ...OutputOption)
- func (f Flags) WriteAfterClose(s string)
- func (f Flags) WriteObject(object interface{}, w io.Writer) error
- type JSONObjectWriter
- type ObjectWriter
- type ObjectWriterOpts
- type OutputOption
- type RowExtractor
- type Streamer
- type TableOptions
- type TableWriter
- type WriterManager
- type YAMLObjectWriter
Constants ¶
const ( // JSONFormat is used to indicate that the output of a command should be in JSON format JSONFormat = "json" // JSONLFormat is used to indicate that the output of a command should be in JSON format using // new line delimited JSON. JSONLFormat = "jsonl" // YAMLFormat is used to indicate that the output of a command should be in YAML format YAMLFormat = "yaml" // TableFormat is used to indicate that the output of a command should be printed as a table TableFormat = "table" )
Variables ¶
var DeprecatedTextColor = color.New(color.FgRed)
DeprecatedTextColor is the color used for deprecation messages.
Functions ¶
func Configv1ChangelogMessage ¶
func Configv1ChangelogMessage(change *models.ResourceChange) string
Configv1ChangelogMessage creates a user readable changelog message.
func Deprecated ¶
Deprecated prints a deprecation message to the given command's stderr with a list of alternative commands.
Types ¶
type ColorPrinter ¶
type ColorPrinter struct {
// contains filtered or unexported fields
}
ColorPrinter prints to a given io.Writer with color.
func NewColorPrinter ¶
func NewColorPrinter(w io.Writer, c *color.Color) ColorPrinter
NewColorPrinter returns a printer that ensures all output is the given color.
func NewStderrPrinter ¶
func NewStderrPrinter(cmd *cobra.Command) ColorPrinter
NewStderrPrinter returns a printer that ensures all output is the color blue.
type FileOperation ¶
type FileOperation interface { MkDirAll(string, os.FileMode) error OpenFile(string, int, os.FileMode) (io.WriteCloser, error) }
FileOperation is an interface that abstracts the file operations for the various writer implementations of chronoctl
type FileOps ¶
type FileOps struct{}
FileOps is the default implementation of FileOperation
type Flags ¶
type Flags struct { // Format is which Format to use when writing output. Format string // Writers maps a Format to a specific writer, allowing commands to register // their own output Format, e.g. a table view. Writers map[string]ObjectWriter // OutputDirectory is the directory where the output is written to. OutputDirectory string // CreateFilePerObject indicates whether to create a file per object. CreateFilePerObject bool // contains filtered or unexported fields }
Flags is a struct that contains the configuration for the output flags
func NewFlags ¶
func NewFlags(opts ...OutputOption) *Flags
NewFlags returns a new Flags object with the given options applied.
func (Flags) NewWriterManager ¶
func (f Flags) NewWriterManager(w io.Writer) (*WriterManager, error)
NewWriterManager returns a writer manager
func (*Flags) WithOutputOptions ¶
func (f *Flags) WithOutputOptions(opts ...OutputOption)
WithOutputOptions allows late application of options.
func (Flags) WriteAfterClose ¶
WriteAfterClose prints out final messages after closing our object writer stream. Use for this can be printing an additional command to be run.
type JSONObjectWriter ¶
type JSONObjectWriter struct {
// contains filtered or unexported fields
}
JSONObjectWriter marshalls and writes JSON to an output stream. Not safe for concurrent use.
func NewJSONObjectWriter ¶
func NewJSONObjectWriter(useArray bool) *JSONObjectWriter
NewJSONObjectWriter returns a new writer for JSON output
func (*JSONObjectWriter) Close ¶
func (j *JSONObjectWriter) Close(w io.Writer, opts ObjectWriterOpts) error
Close closes the object writer stream and prints any final messages.
func (*JSONObjectWriter) WriteAfterClose ¶
func (j *JSONObjectWriter) WriteAfterClose(s string)
WriteAfterClose sets a final message to print after closing our object writer stream.
func (*JSONObjectWriter) WriteObject ¶
func (j *JSONObjectWriter) WriteObject(w io.Writer, obj interface{}, opts ObjectWriterOpts) error
WriteObject marshals and writes a JSON object to the output stream.
type ObjectWriter ¶
type ObjectWriter interface { WriteObject(io.Writer, interface{}, ObjectWriterOpts) error WriteAfterClose(string) Close(io.Writer, ObjectWriterOpts) error }
ObjectWriter marshals an object and streams it to output.
type ObjectWriterOpts ¶
type ObjectWriterOpts struct {
// contains filtered or unexported fields
}
ObjectWriterOpts are options for writing objects.
type OutputOption ¶
type OutputOption func(*Flags) //nolint:revive // ignore repetitive name warning
OutputOption is a function that configures output options for writers
func WithWriter ¶
func WithWriter(formatName string, writer ObjectWriter) OutputOption
WithWriter registers a writer with the given Format name.
func WithoutCreateFilePerObject ¶
func WithoutCreateFilePerObject() OutputOption
WithoutCreateFilePerObject is an option that configuration a writer to not output each object to a separate file.
func WithoutOutputDirectory ¶
func WithoutOutputDirectory() OutputOption
WithoutOutputDirectory disables the out-dir flag
type RowExtractor ¶
RowExtractor takes in an object and extracts a map of header name -> value.
type Streamer ¶
Streamer is a callback for processing an individual entity. If an error is returned, the caller should stop processing results.
func NewWriteObjectStreamer ¶
func NewWriteObjectStreamer[T types.Object](manager *WriterManager) Streamer[T]
NewWriteObjectStreamer streams objects to the io.Writer provided.
type TableOptions ¶
type TableOptions func(*options)
TableOptions is a function that configures a TableWriter.
func SetAutoWrapText ¶
func SetAutoWrapText(autoWrap bool) TableOptions
SetAutoWrapText sets whether or not the table writer should wrap text.
type TableWriter ¶
type TableWriter struct {
// contains filtered or unexported fields
}
TableWriter marshalls and writes objects in a table format to an output stream.
func NewTableWriter ¶
func NewTableWriter(headers []string, extractor RowExtractor, os ...TableOptions) *TableWriter
NewTableWriter returns an object marshaller that renders a table. Headers are essentially the column keys for the table, and extractor takes in a single object and produces a map of header key -> header value. Not safe for concurrent use. The table writer can be customized by passing in options.
func (*TableWriter) Close ¶
func (t *TableWriter) Close(w io.Writer, _ ObjectWriterOpts) error
Close renders the table and prints any final messages.
func (*TableWriter) WriteAfterClose ¶
func (t *TableWriter) WriteAfterClose(s string)
WriteAfterClose sets a final message to print after closing our object writer stream.
func (*TableWriter) WriteObject ¶
func (t *TableWriter) WriteObject(w io.Writer, obj interface{}, _ ObjectWriterOpts) error
WriteObject writes an object in table format to the output stream.
type WriterManager ¶
type WriterManager struct { W io.Writer ObjectWriter ObjectWriter FilePerObj bool Dir string Format string FileOps FileOperation // contains filtered or unexported fields }
WriterManager is a struct that manages the output of chronoctl
func NewWriterManager ¶
func NewWriterManager(flags *Flags, stdout io.Writer, fileOps FileOperation) (*WriterManager, error)
NewWriterManager creates a new WriterManager
func (*WriterManager) WriteObject ¶
func (m *WriterManager) WriteObject(obj types.Object) error
WriteObject writes an object to the output writer
type YAMLObjectWriter ¶
type YAMLObjectWriter struct {
// contains filtered or unexported fields
}
YAMLObjectWriter is an ObjectWriter that marshals and streams yaml.
func NewYAMLObjectWriter ¶
func NewYAMLObjectWriter() *YAMLObjectWriter
NewYAMLObjectWriter returns a new YAMLObjectWriter, which marshals and streams yaml.
func (*YAMLObjectWriter) Close ¶
func (y *YAMLObjectWriter) Close(w io.Writer, _ ObjectWriterOpts) error
Close closes the object writer stream and prints any final messages
func (*YAMLObjectWriter) WriteAfterClose ¶
func (y *YAMLObjectWriter) WriteAfterClose(s string)
WriteAfterClose sets a final message to print after closing our object writer stream.
func (*YAMLObjectWriter) WriteObject ¶
func (y *YAMLObjectWriter) WriteObject(w io.Writer, obj interface{}, opts ObjectWriterOpts) error
WriteObject marshals and writes a YAML object to the output stream.