format

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 23 Imported by: 2

README

go-output

A module used by me to manage outputs in various CLI tools. This uses a mix of external packages and ones I've written. Feel free to use it, but if you only need part of the functionality you might be better of using those modules directly. Functionality and any external tools it uses are documented below.

Output types

This supports various output types:

json
yaml
csv
html
table
markdown
dot
mermaid
draw.io/diagram.net

Usage

Development

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TableStyles = map[string]table.Style{
	"Default":                    table.StyleDefault,
	"Bold":                       table.StyleBold,
	"ColoredBright":              table.StyleColoredBright,
	"ColoredDark":                table.StyleColoredDark,
	"ColoredBlackOnBlueWhite":    table.StyleColoredBlackOnBlueWhite,
	"ColoredBlackOnCyanWhite":    table.StyleColoredBlackOnCyanWhite,
	"ColoredBlackOnGreenWhite":   table.StyleColoredBlackOnGreenWhite,
	"ColoredBlackOnMagentaWhite": table.StyleColoredBlackOnMagentaWhite,
	"ColoredBlackOnYellowWhite":  table.StyleColoredBlackOnYellowWhite,
	"ColoredBlackOnRedWhite":     table.StyleColoredBlackOnRedWhite,
	"ColoredBlueWhiteOnBlack":    table.StyleColoredBlueWhiteOnBlack,
	"ColoredCyanWhiteOnBlack":    table.StyleColoredCyanWhiteOnBlack,
	"ColoredGreenWhiteOnBlack":   table.StyleColoredGreenWhiteOnBlack,
	"ColoredMagentaWhiteOnBlack": table.StyleColoredMagentaWhiteOnBlack,
	"ColoredRedWhiteOnBlack":     table.StyleColoredRedWhiteOnBlack,
	"ColoredYellowWhiteOnBlack":  table.StyleColoredYellowWhiteOnBlack,
}

TableStyles is a lookup map for getting the table styles based on a string

Functions

func PrintByteSlice

func PrintByteSlice(contents []byte, outputFile string, targetBucket S3Output) error

PrintByteSlice prints the provided contents to stdout or the provided filepath

Types

type FromToColumns

type FromToColumns struct {
	From  string
	To    string
	Label string
}

FromToColumns is used to set the From and To columns for graphical output formats

type OutputArray

type OutputArray struct {
	Settings *OutputSettings
	Contents []OutputHolder
	Keys     []string
}

OutputArray holds all the different OutputHolders that will be provided as output, as well as the keys (headers) that will actually need to be printed

func (*OutputArray) AddContents

func (output *OutputArray) AddContents(contents map[string]interface{})

AddContents adds the provided map[string]interface{} to the OutputHolder and that in turn to the OutputArray

func (OutputArray) AddHeader

func (output OutputArray) AddHeader(header string)

func (*OutputArray) AddHolder

func (output *OutputArray) AddHolder(holder OutputHolder)

AddHolder adds the provided OutputHolder to the OutputArray

func (OutputArray) AddToBuffer

func (output OutputArray) AddToBuffer()

func (*OutputArray) ContentsAsInterfaces

func (output *OutputArray) ContentsAsInterfaces() [][]interface{}

func (OutputArray) GetContentsMap

func (output OutputArray) GetContentsMap() []map[string]string

GetContentsMap returns a stringmap of the output contents

func (OutputArray) GetContentsMapRaw

func (output OutputArray) GetContentsMapRaw() []map[string]interface{}

GetContentsMapRaw returns a interface map of the output contents

func (OutputArray) HtmlTableOnly

func (output OutputArray) HtmlTableOnly() []byte

HtmlTableOnly returns a byte array containing an HTML table of the OutputArray

func (*OutputArray) KeysAsInterface

func (output *OutputArray) KeysAsInterface() []interface{}

func (OutputArray) Write

func (output OutputArray) Write()

Write will provide the output as configured in the configuration

type OutputHolder

type OutputHolder struct {
	Contents map[string]interface{}
}

OutputHolder holds key-value pairs that belong together in the output

type OutputSettings

type OutputSettings struct {
	// Defines whether a table of contents should be added
	HasTOC bool
	// The header information for a draw.io/diagrams.net CSV import
	DrawIOHeader drawio.Header
	// FrontMatter can be provided for a Markdown output
	FrontMatter map[string]string
	// The columns for graphical interfaces to show how parent-child relationships connect
	FromToColumns *FromToColumns
	// The type of Mermaid diagram
	MermaidSettings *mermaid.Settings
	// The name of the file the output should be saved to
	OutputFile string
	// The format of the output file
	OutputFileFormat string
	// The format of the output that should be used
	OutputFormat string
	// Store the output in the provided S3 bucket
	S3Bucket S3Output
	// For table heavy outputs, should there be extra spacing between tables
	SeparateTables bool
	// Does the output need to be appended to an existing file?
	ShouldAppend bool
	// For columnar outputs (table, html, csv, markdown) split rows with multiple values into separate rows
	SplitLines bool
	// The key the output should be sorted by
	SortKey string
	// For tables, how wide can a table be?
	TableMaxColumnWidth int
	// The style of the table
	TableStyle table.Style
	// The title of the output
	Title string
	// Should colors be shown in the output
	UseColors bool
	// Should emoji be shown in the output
	UseEmoji bool
}

func NewOutputSettings

func NewOutputSettings() *OutputSettings

NewOutputSettings creates and returns a new OutputSettings object with some default values

func (*OutputSettings) AddFromToColumns

func (settings *OutputSettings) AddFromToColumns(from string, to string)

AddFromToColumns sets from to columns for graphical formats

func (*OutputSettings) AddFromToColumnsWithLabel

func (settings *OutputSettings) AddFromToColumnsWithLabel(from string, to string, label string)

AddFromToColumns sets from to columns for graphical formats

func (*OutputSettings) GetDefaultExtension

func (settings *OutputSettings) GetDefaultExtension() string

func (*OutputSettings) GetSeparator

func (settings *OutputSettings) GetSeparator() string

func (*OutputSettings) NeedsFromToColumns

func (settings *OutputSettings) NeedsFromToColumns() bool

NeedsFromToColumns verifies if a format requires from and to columns to be set

func (*OutputSettings) SetOutputFormat

func (settings *OutputSettings) SetOutputFormat(format string)

SetOutputFormat sets the expected output format

func (*OutputSettings) SetS3Bucket

func (settings *OutputSettings) SetS3Bucket(client *s3.Client, bucket string, path string)

func (*OutputSettings) StringBold

func (settings *OutputSettings) StringBold(text string) string

func (*OutputSettings) StringBoldInline

func (settings *OutputSettings) StringBoldInline(text string) string

func (*OutputSettings) StringFailure

func (settings *OutputSettings) StringFailure(text interface{}) string

func (*OutputSettings) StringInfo

func (settings *OutputSettings) StringInfo(text interface{}) string

func (*OutputSettings) StringPositive

func (settings *OutputSettings) StringPositive(text string) string

func (*OutputSettings) StringPositiveInline

func (settings *OutputSettings) StringPositiveInline(text string) string

func (*OutputSettings) StringSuccess

func (settings *OutputSettings) StringSuccess(text interface{}) string

func (*OutputSettings) StringWarning

func (settings *OutputSettings) StringWarning(text string) string

func (*OutputSettings) StringWarningInline

func (settings *OutputSettings) StringWarningInline(text string) string

type S3Output

type S3Output struct {
	S3Client *s3.Client
	Bucket   string
	Path     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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