cmd

package
v0.0.0-...-288c4de Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableFormatCSV     = "csv"
	TableFormatJSON    = "json"
	TableFormatTable   = "table"
	TableFormatYAML    = "yaml"
	TableFormatCompact = "compact"
)

Table list format.

Variables

This section is empty.

Functions

func AskBool

func AskBool(question string, defaultAnswer string) (bool, error)

AskBool asks a question and expect a yes/no answer.

func AskChoice

func AskChoice(question string, choices []string, defaultAnswer string) (string, error)

AskChoice asks the user to select one of multiple options.

func AskInt

func AskInt(question string, min int64, max int64, defaultAnswer string, validate func(int64) error) (int64, error)

AskInt asks the user to enter an integer between a min and max value.

func AskPassword

func AskPassword(question string) string

AskPassword asks the user to enter a password.

func AskPasswordOnce

func AskPasswordOnce(question string) string

AskPasswordOnce asks the user to enter a password.

It's the same as AskPassword, but it won't ask to enter it again.

func AskString

func AskString(question string, defaultAnswer string, validate func(string) error) (string, error)

AskString asks the user to enter a string, which optionally conforms to a validation function.

func CancelableWait

func CancelableWait(rawOp any, progress *ProgressRenderer) error

CancelableWait waits for an operation and cancel it on SIGINT/SIGTERM.

func FormatSection

func FormatSection(header string, content string) string

FormatSection properly indents a text section.

func RenderSlice

func RenderSlice(data any, format string, displayColumns string, sortColumns string, columnMap map[rune]Column) error

RenderSlice renders the "data" argument, which must be a slice, into a table or as json/yaml as defined by the "format" argument. The "columns" argument defines which columns will be rendered. It will error if the data argument is not a slice, if the format is unrecognized, if any characters in the columns argument is not present in the columnMap argument.

func RenderTable

func RenderTable(format string, header []string, data [][]string, raw any) error

RenderTable renders tabular data in various formats.

func SortByPrecedence

func SortByPrecedence(data [][]string, displayColumns string, sortColumns string) error

SortByPrecedence sorts the given data in order of precedence. Each row of the data argument should have length equal to len(displayColumns). The sortColumns argument should be a subset of displayColumns.

Types

type ByNameAndType

type ByNameAndType [][]string

ByNameAndType represents the type for sorting Storage volumes.

func (ByNameAndType) Len

func (a ByNameAndType) Len() int

func (ByNameAndType) Less

func (a ByNameAndType) Less(i, j int) bool

func (ByNameAndType) Swap

func (a ByNameAndType) Swap(i, j int)

type Column

type Column struct {
	Header string

	// DataFunc is a method to retrieve data for this column. The argument to this function will be an element of the
	// "data" slice that is passed into RenderSlice.
	DataFunc func(any) (string, error)
}

Column represents a single column in a table.

type ProgressRenderer

type ProgressRenderer struct {
	Format string
	Quiet  bool
	// contains filtered or unexported fields
}

ProgressRenderer tracks the progress information.

func (*ProgressRenderer) Done

func (p *ProgressRenderer) Done(msg string)

Done prints the final status and prevents any update.

func (*ProgressRenderer) Update

func (p *ProgressRenderer) Update(status string)

Update changes the status message to the provided string.

func (*ProgressRenderer) UpdateOp

func (p *ProgressRenderer) UpdateOp(op api.Operation)

UpdateOp is a helper to update the status using a LXD API operation.

func (*ProgressRenderer) UpdateProgress

func (p *ProgressRenderer) UpdateProgress(progress ioprogress.ProgressData)

UpdateProgress is a helper to update the status using an iopgress instance.

func (*ProgressRenderer) Warn

func (p *ProgressRenderer) Warn(status string, timeout time.Duration)

Warn shows a temporary message instead of the status.

type SortColumnsNaturally

type SortColumnsNaturally [][]string

SortColumnsNaturally represents the type for sorting columns in a natural order from left to right.

func (SortColumnsNaturally) Len

func (a SortColumnsNaturally) Len() int

func (SortColumnsNaturally) Less

func (a SortColumnsNaturally) Less(i, j int) bool

func (SortColumnsNaturally) Swap

func (a SortColumnsNaturally) Swap(i, j int)

type StringList

type StringList [][]string

StringList represents the type for sorting nested string lists.

func (StringList) Len

func (a StringList) Len() int

func (StringList) Less

func (a StringList) Less(i, j int) bool

func (StringList) Swap

func (a StringList) Swap(i, j int)

Jump to

Keyboard shortcuts

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