Documentation
¶
Index ¶
- Constants
- func CancelableWait(rawOp any, progress *ProgressRenderer) error
- func ColumnData[T any](columns []TypedColumn[T], items []T) [][]string
- func ColumnHeaders[T any](columns []TypedColumn[T]) []string
- func DefaultColumnString[T any](columns []ShorthandColumn[T]) string
- func FormatSection(header string, content string) string
- func FormatStringFlagLabel(flag string) string
- func RenderSlice(data any, format string, displayColumns string, sortColumns string, ...) error
- func RenderTable(format string, header []string, data [][]string, raw any) error
- func SortByPrecedence(data [][]string, displayColumns string, sortColumns string) error
- type Asker
- func (a *Asker) AskBool(question string, defaultAnswer string) (bool, error)
- func (a *Asker) AskChoice(question string, choices []string, defaultAnswer string) (string, error)
- func (a *Asker) AskInt(question string, minimum int64, maximum int64, defaultAnswer string, ...) (int64, error)
- func (a *Asker) AskPassword(question string) string
- func (a *Asker) AskPasswordOnce(question string) string
- func (a *Asker) AskString(question string, defaultAnswer string, validate func(string) error) (string, error)
- type ByNameAndType
- type Column
- type ProgressRenderer
- type ShorthandColumn
- type SortColumnsNaturally
- type StringList
- type TypedColumn
Constants ¶
const ( TableFormatCSV = "csv" TableFormatJSON = "json" TableFormatTable = "table" TableFormatYAML = "yaml" TableFormatCompact = "compact" TableFormatSQLResult = "sql" )
Table list format.
Variables ¶
This section is empty.
Functions ¶
func CancelableWait ¶
func CancelableWait(rawOp any, progress *ProgressRenderer) error
CancelableWait waits for an operation and cancel it on SIGINT/SIGTERM.
func ColumnData ¶
func ColumnData[T any](columns []TypedColumn[T], items []T) [][]string
ColumnData generates table data rows from a slice of items using the given columns.
func ColumnHeaders ¶
func ColumnHeaders[T any](columns []TypedColumn[T]) []string
ColumnHeaders returns the header names from a list of typed columns.
func DefaultColumnString ¶
func DefaultColumnString[T any](columns []ShorthandColumn[T]) string
DefaultColumnString returns the default column string from an ordered slice of column definitions, by concatenating each shorthand rune in order.
func FormatSection ¶
FormatSection properly indents a text section.
func FormatStringFlagLabel ¶
FormatStringFlagLabel formats a command flag label to include the “ at the end of the string to signal cobra to not include the type ("string") in the help output.
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 ¶
RenderTable renders tabular data in various formats.
func SortByPrecedence ¶
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 Asker ¶
type Asker struct {
// contains filtered or unexported fields
}
Asker holds a reader for reading input into CLI questions.
func NewAsker ¶
NewAsker creates a new Asker instance that reads from the given reader. It can also be configured with a logger to help during the debug process.
func (*Asker) AskInt ¶
func (a *Asker) AskInt(question string, minimum int64, maximum int64, defaultAnswer string, validate func(int64) error) (int64, error)
AskInt asks the user to enter an integer between a min and max value.
func (*Asker) AskPassword ¶
AskPassword asks the user to enter a password.
func (*Asker) AskPasswordOnce ¶
AskPasswordOnce asks the user to enter a password.
It's the same as AskPassword, but it won't ask to enter it again.
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 ¶
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.
type ShorthandColumn ¶
ShorthandColumn pairs a shorthand rune with a column definition. Ordered slices of ShorthandColumn are the single source of truth for both the default column string and the shorthand lookup map.
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)
type TypedColumn ¶
TypedColumn defines a table column with a strongly typed data extraction function.
func ParseColumns ¶
func ParseColumns[T any](flagColumns string, shorthandMap map[rune]TypedColumn[T]) ([]TypedColumn[T], error)
ParseColumns parses a comma-separated column specification string against a shorthand map, returning the selected columns. Each character in the string maps to one column via the shorthand map.
func ParseShorthandColumns ¶
func ParseShorthandColumns[T any](flagColumns string, columns []ShorthandColumn[T]) ([]TypedColumn[T], error)
ParseShorthandColumns builds a shorthand map from the given column definitions and parses the flagColumns string against it. It returns an error if any duplicate shorthand runes are found in the column definitions.