Skip to content

Accept plaintext as alias for var_export format#6286

Open
dilipom13 wants to merge 5 commits intowp-cli:mainfrom
dilipom13:fix-4774-plaintext-var-export-alias
Open

Accept plaintext as alias for var_export format#6286
dilipom13 wants to merge 5 commits intowp-cli:mainfrom
dilipom13:fix-4774-plaintext-var-export-alias

Conversation

@dilipom13
Copy link
Copy Markdown

Fixes #4774

  • Treat plaintext as an alias for var_export wherever that output format is used (per maintainer note).
  • Add Utils\is_var_export_format() and use it in param_dump, print_value, and Formatter.
  • Document plaintext in wp cli param-dump and wp cli alias list synopses.
  • Add Behat coverage and a small PHPUnit test for the helper.

Please review it.
Thanks, @schlessera, for the guidance.

@dilipom13 dilipom13 requested a review from a team as a code owner March 21, 2026 15:12
@github-actions
Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@github-actions github-actions bot added command:cli Related to 'cli' command command:cli-alias Related to 'cli alias' command command:cli-param-dump Related to 'cli param-dump' command labels Mar 21, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances WP-CLI's output formatting capabilities by introducing "plaintext" as a convenient alias for the "var_export" format. This change streamlines the user experience by providing a more intuitive option for developers who prefer a plain text representation of data that is still valid PHP. The implementation includes a new utility function for format detection, integration into core output mechanisms, updated command documentation, and comprehensive test coverage to ensure reliability.

Highlights

  • New Output Format Alias: Introduced "plaintext" as an alias for the "var_export" output format across WP-CLI commands, aligning with maintainer notes.
  • Helper Function: Added a new utility function, "Utils\is_var_export_format()", to consistently check for "var_export" or "plaintext" formats.
  • Core Integration: Integrated the new format alias and helper function into "WP_CLI\Formatter", "WP_CLI::print_value", and "CLI_Command::param_dump" for consistent behavior.
  • Documentation Updates: Updated documentation for "wp cli param-dump" and "wp cli alias list" to reflect the availability of the "plaintext" output format.
  • Test Coverage: Expanded test coverage with new Behat scenarios for "aliases", "cli", and "formatter" features, and a PHPUnit test for the "is_var_export_format" utility.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces plaintext as an alias for the var_export output format, enhancing user experience by providing a more intuitive format name. The changes are consistently applied across various commands (cli alias list, cli param-dump) and the Formatter class. A new utility function Utils\is_var_export_format() centralizes the logic, and the new functionality is well-covered by Behat and PHPUnit tests.

My review includes a couple of suggestions to improve code clarity and maintainability.

I am having trouble creating individual review comments. Click here to see my feedback.

php/class-wp-cli.php (1189-1190)

medium

This new elseif block has the same implementation as the one that follows on lines 1191-1192. This creates redundancy. To improve maintainability, you could combine both conditions into a single block.

For example, you could replace lines 1189-1192 with:

} elseif ( Utils\is_var_export_format( Utils\get_flag_value( $assoc_args, 'format' ) ) || is_array( $value ) || is_object( $value ) ) {
    $_value = var_export( $value, true );
}

php/utils.php (494)

medium

The type hint for $format is mixed, which is too general. Based on its usage with Utils\get_flag_value(), this parameter will typically be a string or null. Using a more specific type hint like @param string|null $format would improve code clarity and help static analysis tools.

 * @param string|null $format Format flag value from command arguments.

php/utils.php Outdated
* @param mixed $format Format flag value from command arguments.
* @return bool
*/
function is_var_export_format( $format ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't really need an extra function for this one line check. Let's just inline this everywhere

Copy link
Copy Markdown
Author

@dilipom13 dilipom13 Mar 21, 2026

Choose a reason for hiding this comment

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

Okay @swissspidy, but still I am confused.
Why are so many files failing

I think I need to check more.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Formatter.php 80.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy
Copy link
Copy Markdown
Member

No idea why there are so many test failures 🤔

@dilipom13
Copy link
Copy Markdown
Author

Hello @swissspidy, again, I updated from my side.
Please review it. as per your availability.

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

Labels

command:cli Related to 'cli' command command:cli-alias Related to 'cli alias' command command:cli-param-dump Related to 'cli param-dump' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

var_export vs plaintext

2 participants