utility

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package utility provides utility functionality that is used throughout the Civo CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToYesNo

func BoolToYesNo(d bool) string

BoolToYesNo returns Yes or No depending on the value of a boolean This wouldn't be as necessary if Go had a ternary operator

Types

type OutputWriter

type OutputWriter struct {
	Keys       []string
	Labels     []string
	Values     [][]string
	TempValues []string
}

OutputWriter is for printing structured data in various tabular formats

ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendData("ID", instance.ID)

# Then one of:
ow.WriteSingleObjectJSON()
ow.WriteMultipleObjectsJSON()
ow.WriteCustomOutput(OutputFields)
ow.WriteKeyValues()
ow.WriteTable()

func NewOutputWriter

func NewOutputWriter() *OutputWriter

NewOutputWriter builds a new OutputWriter

func NewOutputWriterWithMap

func NewOutputWriterWithMap(data map[string]string) *OutputWriter

NewOutputWriterWithMap builds a new OutputWriter and automatically inserts the supplied map as a single line

func (*OutputWriter) AppendData

func (ow *OutputWriter) AppendData(key, value string)

AppendData adds a line of data to the output writer

func (*OutputWriter) AppendDataWithLabel

func (ow *OutputWriter) AppendDataWithLabel(key, value, label string)

AppendDataWithLabel adds a line of data to the output writer

func (*OutputWriter) StartLine

func (ow *OutputWriter) StartLine()

StartLine starts a new line of output

func (*OutputWriter) WriteCustomOutput

func (ow *OutputWriter) WriteCustomOutput(fields string)

WriteCustomOutput prints one or multiple objects using custom formatting

func (*OutputWriter) WriteKeyValues

func (ow *OutputWriter) WriteKeyValues()

WriteKeyValues prints a single object stored in the OutputWriter in key: value format

func (*OutputWriter) WriteMultipleObjectsJSON

func (ow *OutputWriter) WriteMultipleObjectsJSON()

WriteMultipleObjectsJSON writes the JSON for multiple objects to STDOUT

func (*OutputWriter) WriteSingleObjectJSON

func (ow *OutputWriter) WriteSingleObjectJSON()

WriteSingleObjectJSON writes the JSON for a single object to STDOUT

func (*OutputWriter) WriteSubheader

func (ow *OutputWriter) WriteSubheader(label string)

WriteSubheader writes a centred heading line in to output

func (*OutputWriter) WriteTable

func (ow *OutputWriter) WriteTable()

WriteTable prints multiple objects stored in the OutputWriter in tabular format

Jump to

Keyboard shortcuts

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