Skip to content

Commit 1fda9c7

Browse files
author
Sam Eer
committed
Fix wp-cli#4774: Standardize plaintext format name across CLI commands
- 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.
1 parent 626c666 commit 1fda9c7

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

‎php/class-wp-cli.php‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,14 +1182,22 @@ public static function read_value( $raw_value, $assoc_args = [] ) {
11821182
*/
11831183
public static function print_value( $value, $assoc_args = [] ) {
11841184
$_value = '';
1185-
if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'json' ) {
1185+
$format = Utils\get_flag_value( $assoc_args, 'format' );
1186+
1187+
// Support deprecated 'var_export' format name
1188+
if ( 'var_export' === $format ) {
1189+
WP_CLI::warning( "The 'var_export' format is deprecated. Please use 'plaintext' instead." );
1190+
$format = 'plaintext';
1191+
}
1192+
1193+
if ( 'json' === $format ) {
11861194
$_value = json_encode( $value );
1187-
} elseif ( Utils\get_flag_value( $assoc_args, 'format' ) === 'yaml' ) {
1195+
} elseif ( 'yaml' === $format ) {
11881196
/**
11891197
* @var array $value
11901198
*/
11911199
$_value = Spyc::YAMLDump( $value, 2, 0 );
1192-
} elseif ( is_array( $value ) || is_object( $value ) ) {
1200+
} elseif ( 'plaintext' === $format || ( is_array( $value ) || is_object( $value ) ) ) {
11931201
$_value = var_export( $value, true );
11941202
} else {
11951203
/**

‎php/commands/src/CLI_Alias_Command.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class CLI_Alias_Command extends WP_CLI_Command {
9090
* options:
9191
* - yaml
9292
* - json
93-
* - var_export
93+
* - plaintext
94+
* - var_export (deprecated, use plaintext)
9495
* ---
9596
*
9697
* [--raw]

‎php/commands/src/CLI_Command.php‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ private function array_find( $arr, $callback ) {
771771
}
772772

773773
/**
774-
* Dumps the list of global parameters, as JSON or in var_export format.
774+
* Dumps the list of global parameters, as JSON or in plaintext format.
775775
*
776776
* ## OPTIONS
777777
*
@@ -783,14 +783,14 @@ private function array_find( $arr, $callback ) {
783783
* ---
784784
* default: json
785785
* options:
786-
* - var_export
786+
* - plaintext
787787
* - json
788788
* ---
789789
*
790790
* ## EXAMPLES
791791
*
792792
* # Dump the list of global parameters.
793-
* $ wp cli param-dump --format=var_export
793+
* $ wp cli param-dump --format=plaintext
794794
* array (
795795
* 'path' =>
796796
* array (
@@ -821,7 +821,13 @@ public function param_dump( $_, $assoc_args ) {
821821
}
822822
}
823823

824-
if ( 'var_export' === Utils\get_flag_value( $assoc_args, 'format' ) ) {
824+
$format = Utils\get_flag_value( $assoc_args, 'format' );
825+
826+
// Support both 'plaintext' and deprecated 'var_export' format names.
827+
if ( 'plaintext' === $format || 'var_export' === $format ) {
828+
if ( 'var_export' === $format ) {
829+
WP_CLI::warning( "The 'var_export' format is deprecated. Please use 'plaintext' instead." );
830+
}
825831
var_export( $spec );
826832
} else {
827833
echo json_encode( $spec );

0 commit comments

Comments
 (0)