Consolidate CLI formatting infrastructure#1385
Open
realrajaryan wants to merge 3 commits intoapple:mainfrom
Open
Consolidate CLI formatting infrastructure#1385realrajaryan wants to merge 3 commits intoapple:mainfrom
realrajaryan wants to merge 3 commits intoapple:mainfrom
Conversation
jglogan
reviewed
Apr 3, 2026
jglogan
reviewed
Apr 3, 2026
7 tasks
96318ea to
92826f9
Compare
jglogan
requested changes
Apr 6, 2026
| } | ||
|
|
||
| /// Renders an `Encodable` value as a JSON string. | ||
| public func renderJSON<T: Encodable>(_ value: T, options: JSONOptions = .compact) throws -> String { |
Contributor
There was a problem hiding this comment.
Prefer methods and properties to free functions (avoids cluttering the global namespace):
https://www.swift.org/documentation/api-design-guidelines/
Also: a helper function could reduce a little bit of boilerplate everywhere:
public func renderOutput<T: ListDisplayable & Encodable>(
_ items: [T], format: ListFormat, quiet: Bool
) throws -> String {
format == .json ? try renderJSON(items) : renderList(items, quiet: quiet)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:ListDisplayableprotocol for table + quiet outputrenderJSON,renderTable,renderListas pure functions that return stringsemit()as the single stdout boundary (no-ops on empty strings to avoid blank-line regressions)JSONOptionsso all JSON encoding goes through one path, including volume inspect's pretty + ISO 8601 caseJSON encoding remains separate from display formatting: each command still chooses its own JSON model, while
ListDisplayableis used only for table and quiet output.ImageListremains the intentional exception for quiet mode so it can avoid unnecessary async work.This change also replaces inline
JSONEncoderusage withrenderJSON, removes the oldCodable+JSON.swifthelper, and movesTableOutputandListFormatintoContainerCommands. It also adds unit tests for the shared rendering helpers and expands integration coverage for image, network, and registry list formatting.Testing