Skip to content

Set column alignment in table-formatted output #206

Closed

Description

@baizmandesign

Feature Request

Describe your use case and the problem you are facing

I'd like to be able to set the alignment of table values when the --format parameter is set to "table."

Here's the output of a custom command I created, which calculates folder sizes, with the current default table column alignment (which is left-aligned):

+------------------+--------+
| Core Directories | Size   |
+------------------+--------+
| mu-plugins       | 8.0K   |
| plugins          | 627.6M |
| themes           | 89.1M  |
| uploads          | 309.2M |
+------------------+--------+

Because the output in the Size column is numerical, it would be easier to read if it were right-aligned, like so:

+------------------+--------+
| Core Directories |   Size |
+------------------+--------+
| mu-plugins       |   8.0K |
| plugins          | 627.6M |
| themes           |  89.1M |
| uploads          | 309.2M |
+------------------+--------+

After perusing the WP-CLI source, it appears there are references to alignment in the Formatter object.

One thing that's unclear to me is the syntax one would use to specify the desired alignments on the command line.

Here's one possibility, where a field position corresponds to the alignment position (the first --fields parameter, "title," corresponds to the first --alignments parameter, "left"):

wp plugin list --fields=title,version --alignments=left,right

Here's another syntactic possibility using a colon as a delimiter between field names and desired alignments:

wp plugin list --fields=title:left,version:right

It's more compact and easier to read, in my opinion.

When the --format parameter is not set to "table," the alignment directives should be ignored.

Activity

  1. swissspidy commented on Jan 28, 2026

    @swissspidy
    Member

    Yeah I just merged alignment support last week, see wp-cli/php-cli-tools#192 and wp-cli/wp-cli#5934.

    One thing that's unclear to me is the syntax one would use to specify the desired alignments on the command line.

    It's not something that you as a user control. Instead, the command developer specifies the alignment. See wp-cli/db-command#252 for an example.

    So in your custom command you would specify that the size column is always right-aligned.

    I don't see why a user would ever want a different alignment, but happy to be proven otherwise.

  2. baizmandesign commented on Jan 28, 2026

    @baizmandesign
    Author

    @swissspidy Oh, this is perfect! (And perfect timing!) Is this part of the next WP-CLI release (2.13.0)? If not, when can I use it in my own projects?

    No need for users to control the alignment. At least, I can't think of a compelling reason when a user would want to intentionally misalign data.

  3. swissspidy commented on Jan 28, 2026

    @swissspidy
    Member

    Yes this will be in the next release!

  4. baizmandesign commented on Jan 28, 2026

    @baizmandesign
    Author

    @swissspidy Fantastic! Thanks again. :-)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions