Skip to content

Provide Go template functions to format table output #3488

@heaths

Description

@heaths

Describe the feature or problem you’d like to solve

Related to #3487 there was no great way to provide table output like you do for most (or perhaps all) your other commands like gh issue list. You expose a color function and I can use printf to align and pad strings, but what would be really great is a table function.

Proposed solution

The Docker CLI lets you specify a table function that works like this:

docker images --format "table {{.Repository}}\t{{.Tag}}"

It would then output something like:

REPOSITORY                               TAG
azuresecuritykeyvaultcertificatestests   latest
dotnet-sdk                               5.0-ubuntu-18.04
jupyter/base-notebook                    latest

This is done via, mostly, https://github.com/docker/cli/blob/daf5f126ad698f34548c21f672450afa5754b7a2/cli/command/formatter/formatter.go. It is effectively like {{range}} but splits on tabs and determines optimal width automatically.

Alternatively, if there was some way to declare the scope of nodes to format as a table automatically, perhaps you could - when specified - format that with survey as you do your own table output.

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIhelp wantedContributions welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions