Skip to content

Standardize plaintext format name across CLI commands#6298

Open
imsameer-dev wants to merge 1 commit intowp-cli:mainfrom
imsameer-dev:main
Open

Standardize plaintext format name across CLI commands#6298
imsameer-dev wants to merge 1 commit intowp-cli:mainfrom
imsameer-dev:main

Conversation

@imsameer-dev
Copy link
Copy Markdown

@imsameer-dev imsameer-dev commented Apr 8, 2026

Description

Standardizes the format parameter name across WP-CLI commands for consistency.

Changes

  • Rename 'var_export' format to 'plaintext' in param-dump command
  • Rename 'var_export' format to 'plaintext' in alias list command
  • Update documentation and examples to reflect new format name
  • The var_export() function output behavior remains the same

Motivation

Different commands were using different names for the same plain-text output format, creating inconsistency in the user experience. This PR standardizes on 'plaintext' which is more descriptive.

Testing

Please verify:

  • wp cli param-dump --format=plaintext works as expected
  • wp cli alias list --format=plaintext works as expected
  • Old var_export format name is no longer accepted (or shows deprecation warning if applicable)

Fixes #4774

@imsameer-dev imsameer-dev requested a review from a team as a code owner April 8, 2026 21:33
Copilot AI review requested due to automatic review settings April 8, 2026 21:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

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-alias Related to 'cli alias' command command:cli-param-dump Related to 'cli param-dump' command command:cli-utils labels Apr 8, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/class-wp-cli.php 0.00% 7 Missing ⚠️
php/commands/src/CLI_Command.php 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Standardizes the plain-text output format name across WP-CLI “cli” subcommands by renaming the var_export format to plaintext, aiming to make --format usage more consistent for users.

Changes:

  • Update wp cli param-dump docs and switch the implementation check from var_export to plaintext.
  • Update wp cli alias list documented/validated --format options to use plaintext instead of var_export.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
php/commands/src/CLI_Command.php Renames the param-dump format flag from var_export to plaintext in docs and runtime branching.
php/commands/src/CLI_Alias_Command.php Renames the alias list format option in the docblock options list to plaintext (affects runtime validation).
Comments suppressed due to low confidence (2)

php/commands/src/CLI_Command.php:828

  • Changing the allowed --format values here drops support for the previously documented var_export format. Because options: in the docblock is used for runtime validation, existing scripts using --format=var_export will now fail with a generic “Invalid value specified for 'format'” error. Consider keeping var_export as an accepted alias for now (and mapping it to plaintext, optionally emitting a deprecation notice to STDERR) to avoid a hard breaking change while still standardizing the preferred name.
	 * [--format=<format>]
	 * : Render output in a particular format.
	 * ---
	 * default: json
	 * options:
	 *   - plaintext
	 *   - json
	 * ---
	 *
	 * ## EXAMPLES
	 *
	 *     # Dump the list of global parameters.
	 *     $ wp cli param-dump --format=plaintext
	 *     array (
	 *       'path' =>
	 *       array (
	 *         'runtime' => '=<path>',
	 *         'file' => '<path>',
	 *         'synopsis' => '',
	 *         'default' => NULL,
	 *         'multiple' => false,
	 *         'desc' => 'Path to the WordPress files.',
	 *       ),
	 *       'url' =>
	 *       array (
	 *
	 * @subcommand param-dump
	 */
	public function param_dump( $_, $assoc_args ) {
		$spec = WP_CLI::get_configurator()->get_spec();

		if ( Utils\get_flag_value( $assoc_args, 'with-values' ) ) {
			$config = WP_CLI::get_configurator()->to_array();
			// Copy current config values to $spec.
			foreach ( $spec as $key => $value ) {
				$current = null;
				if ( isset( $config[0][ $key ] ) ) {
					$current = $config[0][ $key ];
				}
				$spec[ $key ]['current'] = $current;
			}
		}

		if ( 'plaintext' === Utils\get_flag_value( $assoc_args, 'format' ) ) {
			var_export( $spec );
		} else {
			echo json_encode( $spec );
		}

php/commands/src/CLI_Command.php:828

  • There are existing Behat scenarios covering wp cli param-dump default behavior, but none that exercise the new --format=plaintext path (or the expected behavior for the old var_export name). Adding coverage for the plaintext format (and whichever behavior you choose for var_export: rejection vs deprecation alias) would help prevent regressions, especially since options: drives runtime validation.
	 * [--format=<format>]
	 * : Render output in a particular format.
	 * ---
	 * default: json
	 * options:
	 *   - plaintext
	 *   - json
	 * ---
	 *
	 * ## EXAMPLES
	 *
	 *     # Dump the list of global parameters.
	 *     $ wp cli param-dump --format=plaintext
	 *     array (
	 *       'path' =>
	 *       array (
	 *         'runtime' => '=<path>',
	 *         'file' => '<path>',
	 *         'synopsis' => '',
	 *         'default' => NULL,
	 *         'multiple' => false,
	 *         'desc' => 'Path to the WordPress files.',
	 *       ),
	 *       'url' =>
	 *       array (
	 *
	 * @subcommand param-dump
	 */
	public function param_dump( $_, $assoc_args ) {
		$spec = WP_CLI::get_configurator()->get_spec();

		if ( Utils\get_flag_value( $assoc_args, 'with-values' ) ) {
			$config = WP_CLI::get_configurator()->to_array();
			// Copy current config values to $spec.
			foreach ( $spec as $key => $value ) {
				$current = null;
				if ( isset( $config[0][ $key ] ) ) {
					$current = $config[0][ $key ];
				}
				$spec[ $key ]['current'] = $current;
			}
		}

		if ( 'plaintext' === Utils\get_flag_value( $assoc_args, 'format' ) ) {
			var_export( $spec );
		} else {
			echo json_encode( $spec );
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 86 to 94
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: yaml
* options:
* - yaml
* - json
* - var_export
* - plaintext
* ---
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

options: in this docblock is used for runtime validation, so removing var_export here will make wp cli alias list --format=var_export start failing even though the underlying printer would otherwise handle it. If backward compatibility is a goal, consider allowing var_export as an alias (and optionally warning that var_export is deprecated in favor of plaintext).

Copilot uses AI. Check for mistakes.
Comment on lines 86 to 94
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: yaml
* options:
* - yaml
* - json
* - var_export
* - plaintext
* ---
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

There are Behat scenarios for wp cli alias list in YAML/JSON, but none for the newly documented --format=plaintext (and none asserting what should happen with the previous var_export name). Adding a scenario for --format=plaintext (and for var_export depending on whether you keep it as an alias or reject it) would lock in the intended behavior and validation.

Copilot uses AI. Check for mistakes.
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 renames the var_export output format to plaintext within the CLI_Alias_Command and CLI_Command classes. The review feedback correctly identifies that these changes are backward-incompatible, as they remove the var_export option from allowed lists and logic. It is recommended to support both plaintext and var_export to avoid breaking existing user scripts and automation.

* - yaml
* - json
* - var_export
* - plaintext
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Removing var_export from the allowed options list is a breaking change. Existing scripts or aliases that use --format=var_export will now fail validation. It is recommended to keep var_export in the list to maintain backward compatibility, even if plaintext is the new preferred name.

	 *   - plaintext
	 *   - var_export

* default: json
* options:
* - var_export
* - plaintext
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the alias list command, removing var_export from the options list here will break existing usage. It is recommended to keep it as an available option for backward compatibility.

	 *   - plaintext
	 *   - var_export

}

if ( 'var_export' === Utils\get_flag_value( $assoc_args, 'format' ) ) {
if ( 'plaintext' === Utils\get_flag_value( $assoc_args, 'format' ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic change strictly enforces the plaintext format name. Any existing automation using --format=var_export will now fall through to the else block and output JSON instead of the expected PHP var_export format. To avoid breaking changes, both format names should be accepted.

		if ( in_array( Utils\target_flag_value( $assoc_args, 'format' ), [ 'plaintext', 'var_export' ], true ) ) {

- Rename 'var_export' format to 'plaintext' in param-dump command
- Rename 'var_export' format to 'plaintext' in alias list command
- Update documentation and examples to reflect new format name
- var_export() function output behavior remains the same

The plaintext format name is more descriptive and consistent across
both the param-dump and alias list commands.
@swissspidy swissspidy changed the title Fix #4774: Standardize plaintext format name across CLI commands Standardize plaintext format name across CLI commands Apr 9, 2026
@swissspidy
Copy link
Copy Markdown
Member

Note that there is already another PR that aims to resolve the same issue:

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

var_export vs plaintext

3 participants