Documentation ¶
Index ¶
Constants ¶
View Source
const ( BlockLine = "line" BlockTable = "table" )
Variables ¶
View Source
var CSV = Format{ FlagValue: "csv", WriteCollection: func(w io.Writer, r types.CollectionResponse) error { return writeCsv(w, r.DisplayHeaders(), r.Items()) }, WriteSingle: func(w io.Writer, r types.SingleResponse) error { return writeCsv(w, r.DisplayHeaders(), []map[string]interface{}{r.Fields()}) }, }
View Source
var JSON = Format{ FlagValue: "json", WriteCollection: func(w io.Writer, r types.CollectionResponse) error { return writeJson(w, r.Items()) }, WriteSingle: func(w io.Writer, r types.SingleResponse) error { return writeJson(w, r.Fields()) }, }
View Source
var Raw = Format{ FlagValue: "raw", WriteCollection: func(w io.Writer, r types.CollectionResponse) error { return writeJson(w, r) }, WriteSingle: func(w io.Writer, r types.SingleResponse) error { return writeJson(w, r) }, }
View Source
var Table = Format{ FlagValue: "table", WriteCollection: func(w io.Writer, cr types.CollectionResponse) error { items := cr.Items() headers := cr.DisplayHeaders() if len(items) == 0 { return nil } table := tablewriter.NewWriter(w) ConfigureTableWriter(table) table.SetHeader(headers.Names()) row := make([]string, len(headers)) for _, item := range items { FillRowFromHeaders(headers, item, row) table.Append(row) } table.Render() return nil }, WriteSingle: func(w io.Writer, r types.SingleResponse) error { fields := r.Fields() foundFields := 0 table := tablewriter.NewWriter(w) ConfigureTableWriter(table) for _, h := range r.DisplayHeaders() { val, ok := fields[h.Key] if ok { table.Append([]string{h.Name, ToString(val)}) foundFields++ } } if foundFields > 0 { table.Render() } return nil }, }
Functions ¶
func ConfigureTableWriter ¶
func ConfigureTableWriter(table *tablewriter.Table)
func FillRowFromHeaders ¶
func FillRowFromHeaders(headers types.DisplayHeaders, item map[string]interface{}, row []string)
func FormatFlagValues ¶
func FormatFlagValues() []string
Types ¶
type Block ¶
type Block struct { Type string `json:"type"` RawValue json.RawMessage `json:"value"` }
func (Block) TableValue ¶
func (b Block) TableValue() (t TabularData)
type Format ¶
type Format struct { // The string value of this format to use in a CLI flag, like 'csv' or 'json'. FlagValue string // Write the API collection response with "display_headers" and "items" to w. WriteCollection func(io.Writer, types.CollectionResponse) error // Write the API response with "display_headers" to w. // Should not have 'items', instead uses display_headers to pluck // fields from the response. WriteSingle func(io.Writer, types.SingleResponse) error }
func LookupByFlag ¶
type TabularData ¶
Click to show internal directories.
Click to hide internal directories.