Skip to content

[Hackathon] feat(cli): add --output csv and --output ndjson for list commands #164

Description

@crypticsaiyan

Discord Username / User ID

uisupersaiyan3

What does this improvement do?

The only machine-readable output today is --output json, which for the paginated list surfaces emits a single buffered, pretty-printed array (out.print({ runs, nextCursor }, ...) in runResultHistory at src/commands/test.ts:3735, test runList at :419, project runList at src/commands/project.ts:47). That shape is awkward for the two most common scripting consumers: spreadsheets and awk (must hand-parse JSON), and line-oriented pipelines (jq or while read must buffer and slice the whole array). This adds two modes to the existing --output enum. --output csv emits an RFC 4180 table: a header row, then one row per item, with columns derived from the response type so they cannot drift. --output ndjson emits one compact JSON object per line with no wrapping array, streamed as each page arrives, so ... --output ndjson | jq -c 'select(.status=="failed")' works without buffering. Both apply to the list commands only (test result --history, project list, test list); a single-object command given --output csv or --output ndjson exits 5 with a clear message. It drops straight into shell CI and data pipelines.

Details / implementation notes

Extend OutputMode (src/lib/output.ts:1) to 'json' | 'text' | 'csv' | 'ndjson' and widen isOutputMode (:12); because --output is validated at one choke point (src/index.ts:128, :140) the new modes stay uniform across command groups. Reuse (do not re-implement) the existing render call sites: runResultHistory (src/commands/test.ts:3735, table via renderRunHistoryTable :3860), test runList (:419, renderTestListText :473), project runList (src/commands/project.ts:47), by adding csv and ndjson branches alongside the current json/text branch in each. Row columns come from the source-of-truth types (RunHistoryItem, CliTest, CliProject), never hand-listed. csv quoting follows RFC 4180 (fields containing , " or a newline are wrapped, " is doubled; null/absent renders as an empty field). ndjson writes one line per row incrementally across the existing cursor loop and routes pagination metadata (nextCursor, short-page hints) to stderr so stdout stays pure ndjson. --output json and --output text remain byte-identical; exit codes are unchanged except exit 5 when csv or ndjson is used on a non-list command. No new dependency. Tests: csv quoting edge cases, multi-page accumulation, ndjson line shape, stdout/stderr separation, non-list rejection exit 5, json/text unchanged. PR to follow once assigned.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedTriaged and accepted — a PR for this will be reviewedhackathonCLI hackathon submissionsin-progressAssigned and actively being worked on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions