utils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyString = ""

Variables

View Source
var TableHeaderOrder []string

Functions

func CreateTable

func CreateTable(data *TableData, tableWriter io.Writer) terminal.Table

func DerefValue

func DerefValue(thing reflect.Value) reflect.Value

Return the dereferenced value if a pointer or interface, hand the value back if not.

func GetArrayElementType

func GetArrayElementType(value reflect.Value) reflect.Kind

for an array value, get the "Kind" of its individual elements

func GetLastQuerySegment

func GetLastQuerySegment(query string) string

If there was a jmespath query against the data, this function will extract the final segment as it may need to be used as a column header. If no query was given, use a default of "values".

func GetStringValue

func GetStringValue(thing reflect.Value) string

Takes the final value that is to be written to the table and formats it as a string if possible.

func HasExactlyOneArrayProperty

func HasExactlyOneArrayProperty(thing reflect.Value) bool

Returns true if the value is a map that has exactly one property that is an array.

func IsArrayType

func IsArrayType(kind reflect.Kind) bool

returns true if kind is Slice or Array returns false otherwise

func IsValidTableData

func IsValidTableData(data *TableData) bool

validates the data to ensure a table can be printed returns false if the table doesn't have sufficient data

Types

type CustomPrinterFunc

type CustomPrinterFunc func(interface{}) bool

type TableData

type TableData struct {
	Headers []string
	Values  [][]string
}

func FormatTableData

func FormatTableData(result interface{}, jmesQuery string) *TableData

type Utils

type Utils struct {
	OutputFormat string
	JMESQuery    string
	// contains filtered or unexported fields
}

func NewUtils

func NewUtils(ui terminal.UI) *Utils

func (*Utils) CheckResponseForError

func (u *Utils) CheckResponseForError(response *core.DetailedResponse, err error) (bool, interface{})

func (*Utils) ConfirmDelete

func (u *Utils) ConfirmDelete(force bool) bool

func (*Utils) ConfirmRunningCommand

func (u *Utils) ConfirmRunningCommand()

func (*Utils) CreateErrorWithMessage

func (u *Utils) CreateErrorWithMessage(err error, msg string) error

Creates a new error with a descriptive message placed before the original error message. This is only used for interactive mode.

func (*Utils) ExposeJMESQueryVar

func (u *Utils) ExposeJMESQueryVar() *string

func (*Utils) ExposeOutputFormatVar

func (u *Utils) ExposeOutputFormatVar() *string

func (*Utils) GetAuthenticator

func (u *Utils) GetAuthenticator(serviceName string) (core.Authenticator, error)

func (*Utils) GetCommandName

func (u *Utils) GetCommandName() string

func (*Utils) GetJMESQuery

func (u *Utils) GetJMESQuery() string

func (*Utils) GetJsonStringAsBytes

func (u *Utils) GetJsonStringAsBytes(json string) (stringAsBytes []byte)

func (*Utils) GetOutputFormat

func (u *Utils) GetOutputFormat() string

func (*Utils) GetPluginConfig

func (u *Utils) GetPluginConfig() plugin.PluginConfig

func (*Utils) GetRegionFromContext

func (u *Utils) GetRegionFromContext() string

func (*Utils) GetResult

func (u *Utils) GetResult(response *core.DetailedResponse, err error) (interface{}, interface{}, error)

func (*Utils) GetServiceURL

func (u *Utils) GetServiceURL(GetServiceURLForRegion func(string) (string, error)) string

func (*Utils) HandleError

func (u *Utils) HandleError(err error, message string)

func (*Utils) HandleErrorResponse

func (u *Utils) HandleErrorResponse(errorBody interface{})

func (*Utils) HandleErrorResponseImpl

func (u *Utils) HandleErrorResponseImpl(errorBody interface{})

func (*Utils) InitializeLogger

func (u *Utils) InitializeLogger(quiet bool)

func (*Utils) MakeResultGeneric

func (u *Utils) MakeResultGeneric(result interface{}) interface{}

func (*Utils) NonZeroExit

func (u *Utils) NonZeroExit()

Exit the program with a non-zero exit code. This should only be called in an error situation.

func (*Utils) Ok

func (u *Utils) Ok()

func (*Utils) OutputIsNotMachineReadable

func (u *Utils) OutputIsNotMachineReadable() bool

func (*Utils) PostProcessServiceConfiguration

func (u *Utils) PostProcessServiceConfiguration(service *core.BaseService, serviceName string) error

func (*Utils) PrintJSON

func (u *Utils) PrintJSON(result interface{})

func (*Utils) PrintJSONImpl

func (u *Utils) PrintJSONImpl(result interface{})

func (*Utils) PrintOutput

func (u *Utils) PrintOutput(result interface{}, tableWriter io.Writer)

func (*Utils) PrintOutputImpl

func (u *Utils) PrintOutputImpl(result interface{}, tableWriter io.Writer)

func (*Utils) ProcessBinaryResponse

func (u *Utils) ProcessBinaryResponse(response *core.DetailedResponse, err error, outputFilename string)

func (*Utils) ProcessEmptyResponse

func (u *Utils) ProcessEmptyResponse(response *core.DetailedResponse, err error)

func (*Utils) ProcessResponse

func (u *Utils) ProcessResponse(response *core.DetailedResponse, err error)

func (*Utils) Prompt

func (u *Utils) Prompt(message string, options *terminal.PromptOptions) *terminal.Prompt

func (*Utils) ReadAsFile

func (u *Utils) ReadAsFile(userInput string) bool

func (*Utils) Say

func (u *Utils) Say(message string)

func (*Utils) SetCommandName

func (u *Utils) SetCommandName(args []string)

store the name of the currently executed command to enable context-aware logic in the utilities

func (*Utils) SetContext

func (u *Utils) SetContext(c plugin.PluginContext)

func (*Utils) SetJMESQuery

func (u *Utils) SetJMESQuery(value string)

func (*Utils) SetOutputFormat

func (u *Utils) SetOutputFormat(value string)

func (*Utils) SetServiceErrorMessages

func (u *Utils) SetServiceErrorMessages(msgs map[string]string)

func (*Utils) SetTableHeaderOrder

func (u *Utils) SetTableHeaderOrder(order []string)

func (*Utils) ValidateRequiredFlags

func (u *Utils) ValidateRequiredFlags(required []string, flags *pflag.FlagSet, serviceName string) error

func (*Utils) WriteFile

func (u *Utils) WriteFile(fileInterface interface{}, filename string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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