Documentation
¶
Index ¶
- Variables
- func Filter(objects map[any]any, filterList []string) map[any]any
- func JSONStringToInterface(jsonString string) interface{}
- func PrintJSONChecked(objects interface{}, format string, rawStrings bool, writer io.Writer) error
- func PrintJSONEvent(writer io.Writer, data []byte) error
- func StyledText(writer io.Writer, text string, attributes ...color.Attribute) string
- func ValidateJSONFormat(format string) error
- type AddFlagsOption
- func WithAdditionalTypes(types ...Type) AddFlagsOption
- func WithDefaultOutput(t Type) AddFlagsOption
- func WithDefaultPipe(t Type) AddFlagsOption
- func WithDefaultTTY(t Type) AddFlagsOption
- func WithFilterFlagDisabled() AddFlagsOption
- func WithPrettyBinding(pb PrettyBinding) AddFlagsOption
- func WithTableBinding(tb *TableBinding) AddFlagsOption
- type Graph
- type GraphPoint
- type Hyperlink
- type JSON
- type Output
- func (o *Output) AddFlags(cmd *cobra.Command, defaultOutput Type, additionalTypes ...Type)deprecated
- func (o *Output) AddFlagsWithOpts(cmd *cobra.Command, opts ...AddFlagsOption)
- func (o *Output) ConfiguredOutputTypes() []string
- func (o *Output) ConfiguredOutputTypesString() string
- func (o *Output) Print(cmd *cobra.Command, objects any)
- type Pretty
- type PrettyBinding
- type StyledCell
- type Table
- type TableBinding
- type Type
Constants ¶
This section is empty.
Variables ¶
var AllTypes = []Type{ JSONType, JQType, TableType, PrettyType, }
AllTypes lists the output types that every command supports.
Functions ¶
func JSONStringToInterface ¶ added in v0.26.0
func JSONStringToInterface(jsonString string) interface{}
func PrintJSONChecked ¶ added in v0.35.0
PrintJSONChecked preserves JSON versus jq raw-string output semantics while returning filter/encoding/write failures to the command. Results are buffered so a runtime filter error does not leave a misleading partial JSON stream. Existing Print callers retain their historical logging behavior.
func PrintJSONEvent ¶ added in v0.33.2
PrintJSONEvent writes one event immediately: indented JSON on a terminal, or a single compact JSON line when redirected. It preserves JSON numbers.
func StyledText ¶ added in v0.35.0
StyledText uses the same terminal and colour preferences as table cells.
Types ¶
type AddFlagsOption ¶ added in v0.29.0
type AddFlagsOption func(*addFlagsConfig)
AddFlagsOption is a functional option for AddFlagsWithOpts.
func WithAdditionalTypes ¶ added in v0.29.0
func WithAdditionalTypes(types ...Type) AddFlagsOption
WithAdditionalTypes adds extra output types to the flag help text.
func WithDefaultOutput ¶ added in v0.29.0
func WithDefaultOutput(t Type) AddFlagsOption
WithDefaultOutput sets the fixed default output type.
func WithDefaultPipe ¶ added in v0.31.0
func WithDefaultPipe(t Type) AddFlagsOption
WithDefaultPipe sets the output type used when stdout is not a TTY and the user has not specified --output.
func WithDefaultTTY ¶ added in v0.31.0
func WithDefaultTTY(t Type) AddFlagsOption
WithDefaultTTY sets the output type used when stdout is a TTY and the user has not specified --output. Implies WithDefaultPipe must also be set; together they cause the flag default to become "auto".
func WithFilterFlagDisabled ¶ added in v0.29.0
func WithFilterFlagDisabled() AddFlagsOption
WithFilterFlagDisabled disables the -f / --filter flag.
func WithPrettyBinding ¶ added in v0.31.0
func WithPrettyBinding(pb PrettyBinding) AddFlagsOption
WithPrettyBinding enables pretty output and sets its binding.
func WithTableBinding ¶ added in v0.29.0
func WithTableBinding(tb *TableBinding) AddFlagsOption
WithTableBinding enables table output and sets its binding.
type Graph ¶ added in v0.33.2
type Graph struct {
Title string
Points []GraphPoint
Bars bool
// Width is measured in terminal columns; zero detects the terminal size.
Width int
}
Graph renders a time series or horizontal ranking without changing the data.
type GraphPoint ¶ added in v0.33.2
GraphPoint is an observation or a ranked value. Time is required for line charts.
type Hyperlink ¶ added in v0.33.2
Hyperlink keeps a cell's label separate from its destination so truncation and alignment happen before terminal escape sequences are added.
type JSON ¶
type JSON struct {
Objects interface{}
Format string
}
func NewJSONFromString ¶ added in v0.26.0
type Output ¶
type Output struct {
Type string
Filter []string
Format string
TableBinding *TableBinding
PrettyBinding PrettyBinding
// contains filtered or unexported fields
}
Output holds the output configuration for a command.
func (*Output) AddFlags
deprecated
AddFlags adds output-related flags to cmd using a positional default and optional extra types.
Deprecated: prefer AddFlagsWithOpts which uses the functional-option pattern and supports smart TTY/pipe defaults.
func (*Output) AddFlagsWithOpts ¶ added in v0.29.0
func (o *Output) AddFlagsWithOpts(cmd *cobra.Command, opts ...AddFlagsOption)
AddFlagsWithOpts adds output-related flags to cmd using the functional-option pattern. When both WithDefaultTTY and WithDefaultPipe are provided the flag default becomes "auto", which resolves at print-time based on whether stdout is a terminal.
func (*Output) ConfiguredOutputTypes ¶ added in v0.17.0
func (*Output) ConfiguredOutputTypesString ¶ added in v0.17.0
type Pretty ¶ added in v0.31.0
type Pretty struct {
// contains filtered or unexported fields
}
Pretty holds the state for a grouped pretty-print run.
func (*Pretty) AddItem ¶ added in v0.31.0
AddItem adds an item string to a named section, creating the section if needed.
func (*Pretty) InitSection ¶ added in v0.31.0
InitSection registers a section without any items.
type PrettyBinding ¶ added in v0.31.0
type PrettyBinding func(interface{}, *Pretty)
PrettyBinding populates a Pretty from objects.
type StyledCell ¶ added in v0.35.0
StyledCell adds a semantic colour to a table cell while retaining its plain string representation for width calculations and redirected output.
func (StyledCell) String ¶ added in v0.35.0
func (c StyledCell) String() string
type Table ¶
type Table struct {
Headings []interface{}
Rows [][]interface{}
// TrimSpace trims leading and trailing whitespace from every cell before rendering.
TrimSpace bool
// ColumnMaxWidths holds the maximum character width for each column (0 = unlimited).
ColumnMaxWidths []int
}
func TableFromObjects ¶
type TableBinding ¶
type TableBinding struct {
Headings []string
// ProcessObjects receives the full object collection and populates the table.
// Use this when per-row extraction needs custom logic (e.g. nested maps).
ProcessObjects func(interface{}, *Table)
// RowExtractor is a simpler alternative to ProcessObjects.
// When set (and ProcessObjects is nil) the library iterates over the
// object collection and calls RowExtractor for each element.
// Return nil to skip a row.
RowExtractor func(interface{}) []string
// ColumnMaxWidths holds the maximum character width for each column (0 = unlimited).
ColumnMaxWidths []int
// TrimSpace trims leading/trailing whitespace from every cell before rendering.
TrimSpace bool
}
TableBinding configures how objects are rendered as a table.
type Type ¶ added in v0.17.0
type Type string
Type is the output format identifier.
const ( JSONType Type = "json" JQType Type = "jq" TableType Type = "table" PrettyType Type = "pretty" // AutoType selects ttyDefault or pipeDefault based on whether stdout is a TTY. // It is used as the flag default when WithDefaultTTY / WithDefaultPipe are set. AutoType Type = "auto" // WebType is a special type for opening a browser. // It is not included in AllTypes and must be passed as an additional type. WebType Type = "web" )
These are the different output types.
Source Files
¶
- checked_json.go
- color.go
- filter.go
- graph.go
- hyperlink.go
- jq.go
- json.go
- json_event.go
- pretty.go
- root.go
- table.go
- width.go