Support formatting account API commands as tables, tsv, yaml, json, or text #569
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.
Problem
The current formatting pattern for each of our account API commands is bespoke. We're soon introducing additional support for Account API commands, and we don't want to create even more bespoke outputs.
Solution
Introduce
createFormatter
that curries an internal function,toFormat
, with a command/output-specific configuration.Then, within the command, outputting becomes as straight-forward as:
Any command that uses
FORMATTABLE_OPTIONS
will get access to the format argument to use with the formatter.To not collide with
colorize
and the existingFormat
enum, the existingFormat
has ben renamed toLanguage
to better align with the fact that it's actually the language being highlighted vs an output format.The expectation is that
createFormatter
will be used with any Account API or CRUD-like command operating on a resource. Querying and schema and other core APIs will continue to usecolorize
directly or other bespoke outputs.Result
This has been applied to the only "account-like" APIs in the CLI atm,
db list
anddb create
. Once more account API commands end up in the CLI, we'll expand its usage.Testing
Command tests have been updated. Need to add tests for the factory, and will do before it's out of draft.