Skip to content

A single-object result has no correct rendering: table errors, csv makes one cell #752

Closed

Description

@David-Noble-at-work

A result that is a single object -- one layer, one package, one run -- has no correct rendering.

$ writ ... -o table
Error: result.TableFormatter: expected slice or array, got map[string]interface {}

$ writ ... -o csv
"map[name:x state:active]"          <- the whole record in one cell

Two different wrong answers to the shape a command produces whenever it reports on one thing.

Cause

TableFormatter.Format (pkg/result/table.go:66) rejects anything that is not a slice or array.
DelimitedFormatter.Format (pkg/result/delimited.go:110) treats any non-sequence as a single cell -- a
carve-out that is right for a scalar, since --jq '.count' depends on it, but wrong for an object.

Fix

A lone record is a sequence of one: headers from its keys, one row of values. A scalar stays one cell.

NAME  STATE
x     active

This is shape S3 in docs/architecture/10-command-line-interface.md §8.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions