Skip to content

Consolidate CLI formatting infrastructure#1385

Merged
realrajaryan merged 4 commits intoapple:mainfrom
realrajaryan:consolidate-cli-formatting
Apr 7, 2026
Merged

Consolidate CLI formatting infrastructure#1385
realrajaryan merged 4 commits intoapple:mainfrom
realrajaryan:consolidate-cli-formatting

Conversation

@realrajaryan
Copy link
Copy Markdown
Contributor

Motivation and Context

This PR consolidates duplicated list-output formatting across the CLI into shared rendering infrastructure.

Currently, each list command has its own copy of the same json/quiet/table branching. This PR pulls that into shared rendering infrastructure in ContainerCommands:

  • ListDisplayable protocol for table + quiet output
  • renderJSON, renderTable, renderList as pure functions that return strings
  • emit() as the single stdout boundary (no-ops on empty strings to avoid blank-line regressions)
  • JSONOptions so all JSON encoding goes through one path, including volume inspect's pretty + ISO 8601 case

JSON encoding remains separate from display formatting: each command still chooses its own JSON model, while ListDisplayable is used only for table and quiet output. ImageList remains the intentional exception for quiet mode so it can avoid unnecessary async work.

This change also replaces inline JSONEncoder usage with renderJSON, removes the old Codable+JSON.swift helper, and moves TableOutput and ListFormat into ContainerCommands. It also adds unit tests for the shared rendering helpers and expands integration coverage for image, network, and registry list formatting.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@github-actions github-actions bot added the cli label Apr 3, 2026
@realrajaryan realrajaryan requested a review from jglogan April 3, 2026 21:25
@realrajaryan realrajaryan force-pushed the consolidate-cli-formatting branch from 96318ea to 92826f9 Compare April 6, 2026 20:34
@realrajaryan realrajaryan requested a review from jglogan April 7, 2026 07:34
@realrajaryan realrajaryan merged commit 3366916 into apple:main Apr 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants