Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support line breaks and tab replacement in tabular table values #182

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

mrsdizzie
Copy link
Member

This adds the same functionality from both #179 and #181 to the tabular table output. In WP CLI behat tests, the 'table containing rows' check can only use tabular table output so we need to fix it here as well in order for tests to work (as seen in wp-cli/wp-cli#6055).

Before:

post_id	meta_key	meta_value
1	foo	foo
1	fruits	apple
banana
mango
1	bar	br

After:

post_id	meta_key	meta_value
1	foo	foo
1	fruits	apple
		banana
		mango
1	bar	br

This adds the same functionality from both #179 and #181 to the tabular
table output. In WP CLI behat tests, the 'table containing rows' check
can only use tabular output so we need to fix it here in order for tests
to work.
@mrsdizzie mrsdizzie requested a review from a team as a code owner March 4, 2025 15:17
@mrsdizzie mrsdizzie added this to the 0.12.3 milestone Mar 4, 2025
@mrsdizzie
Copy link
Member Author

I verified that the test in that PR which was failing now works with this new code:

$ composer behat -vvvv -- features/formatter.feature:157 --format pretty

Feature: Format output

  Scenario: Table rows containing linebreaks            # features/formatter.feature:157
.    Given an empty directory                            # WP_CLI\Tests\Context\FeatureContext::given_an_empty_directory()
.    And a file.php file:                                # WP_CLI\Tests\Context\FeatureContext::given_a_specific_file()
      """
      <?php
      $items      = array(
        (object) array(
          'post_id'    => 1,
          'meta_key'   => 'foo',
          'meta_value' => 'foo',
        ),
        (object) array(
          'post_id'    => 1,
          'meta_key'   => 'fruits',
          'meta_value' => "apple\nbanana\nmango",
        ),
        (object) array(
          'post_id'    => 1,
          'meta_key'   => 'bar',
          'meta_value' => 'br',
        ),
      );
      $assoc_args = array();
      $formatter  = new WP_CLI\Formatter( $assoc_args, array( 'post_id', 'meta_key', 'meta_value' ) );
      $formatter->display_items( $items );
      """
.    When I run `wp eval-file file.php --skip-wordpress` # WP_CLI\Tests\Context\FeatureContext::when_i_run()
.    Then STDOUT should be a table containing rows:      # WP_CLI\Tests\Context\FeatureContext::then_stdout_should_be_a_table_containing_rows()
      | post_id | meta_key | meta_value |
      | 1       | foo      | foo        |
      | 1       | fruits   | apple      |
      |         |          | banana     |
      |         |          | mango      |
      | 1       | bar      | br         |



1 scenario (1 passed)
4 steps (4 passed)
0m0.55s (11.60Mb)

Copy link
Member

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thanks!

@swissspidy swissspidy merged commit 1556134 into master Mar 4, 2025
17 checks passed
@swissspidy swissspidy deleted the newline-tabular-table branch March 4, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants