From 662ee1f32a1d9243e4f8bbe52c002d3afc8a3fb4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 09:57:39 +0000 Subject: [PATCH 1/6] Initial plan From 234783f91387e2854b2c58b3d4ad6e949cc2f665 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 10:03:29 +0000 Subject: [PATCH 2/6] Add --format argument support to core install command Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/language-core.feature | 47 ++++++++++++++++++++++++++++++++++ src/Core_Language_Command.php | 37 +++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/features/language-core.feature b/features/language-core.feature index 4fe8e115..b3d9b56a 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -476,3 +476,50 @@ Feature: Manage core translation files for a WordPress install | en_US | active | | nl_NL | installed | And STDERR should be empty + + @require-wp-4.0 + Scenario: Install languages with different output formats + Given a WP install + And an empty cache + + When I run `wp language core install de_DE nl_NL --format=csv` + Then the return code should be 0 + And STDOUT should be: + """ + locale,status + de_DE,installed + nl_NL,installed + """ + And STDERR should be empty + + When I run `wp language core install de_DE nl_NL --format=summary` + Then the return code should be 0 + And STDOUT should contain: + """ + Success: Installed 0 of 2 languages (2 skipped). + """ + And STDERR should be empty + + When I run `wp language core install de_DE nl_NL invalid_lang --format=json` + Then the return code should be 0 + And STDOUT should be JSON containing: + """ + [{"locale":"de_DE","status":"already installed"},{"locale":"nl_NL","status":"already installed"},{"locale":"invalid_lang","status":"not available"}] + """ + And STDERR should be empty + + When I run `wp language core install fr_FR --format=table` + Then the return code should be 0 + And STDOUT should contain: + """ + locale + """ + And STDOUT should contain: + """ + fr_FR + """ + And STDOUT should contain: + """ + installed + """ + And STDERR should be empty diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index c1b01af1..6a79a0ad 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -183,6 +183,17 @@ public function is_installed( $args ) { * [--activate] * : If set, the language will be activated immediately after install. * + * [--format=] + * : Render output in a particular format. Used when installing multiple languages. + * --- + * default: table + * options: + * - table + * - csv + * - json + * - summary + * --- + * * ## EXAMPLES * * # Install the Brazilian Portuguese language. @@ -198,7 +209,7 @@ public function is_installed( $args ) { * @subcommand install * * @param string[] $args Positional arguments. - * @param array{activate?: bool} $assoc_args Associative arguments. + * @param array{activate?: bool, format: string} $assoc_args Associative arguments. */ public function install( $args, $assoc_args ) { $language_codes = (array) $args; @@ -208,15 +219,30 @@ public function install( $args, $assoc_args ) { WP_CLI::error( 'Only a single language can be active.' ); } + if ( empty( $assoc_args['format'] ) ) { + $assoc_args['format'] = 'table'; + } + + if ( in_array( $assoc_args['format'], array( 'json', 'csv' ), true ) ) { + $logger = new \WP_CLI\Loggers\Quiet(); + \WP_CLI::set_logger( $logger ); + } + $available = $this->get_installed_languages(); + $results = array(); + $successes = 0; $errors = 0; $skips = 0; foreach ( $language_codes as $language_code ) { + $result = [ + 'locale' => $language_code, + ]; if ( in_array( $language_code, $available, true ) ) { \WP_CLI::log( "Language '{$language_code}' already installed." ); + $result['status'] = 'already installed'; ++$skips; } else { $response = $this->download_language_pack( $language_code ); @@ -227,12 +253,15 @@ public function install( $args, $assoc_args ) { // Skip if translation is not yet available. if ( 'not_found' === $response->get_error_code() ) { + $result['status'] = 'not available'; ++$skips; } else { + $result['status'] = 'not installed'; ++$errors; } } else { \WP_CLI::log( "Language '{$language_code}' installed." ); + $result['status'] = 'installed'; ++$successes; } } @@ -240,6 +269,12 @@ public function install( $args, $assoc_args ) { if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'activate' ) ) { $this->activate_language( $language_code ); } + + $results[] = (object) $result; + } + + if ( 'summary' !== $assoc_args['format'] ) { + \WP_CLI\Utils\format_items( $assoc_args['format'], $results, array( 'locale', 'status' ) ); } \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); From f6f267dd44d70918f131ba6b951dde7430b74285 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 10:05:26 +0000 Subject: [PATCH 3/6] Make format parameter optional in docblock type annotation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Language_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 6a79a0ad..3ca79de7 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -209,7 +209,7 @@ public function is_installed( $args ) { * @subcommand install * * @param string[] $args Positional arguments. - * @param array{activate?: bool, format: string} $assoc_args Associative arguments. + * @param array{activate?: bool, format?: string} $assoc_args Associative arguments. */ public function install( $args, $assoc_args ) { $language_codes = (array) $args; From de911add12369961315c82678c14d0c75a712b9e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 10:53:16 +0000 Subject: [PATCH 4/6] Fix: Only output formatted results when --format flag is explicitly provided The previous implementation always outputted formatted tables, breaking existing tests. Now format output is only shown when user explicitly provides --format flag, preserving backward compatibility. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Language_Command.php | 42 ++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 3ca79de7..d207ed35 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -219,13 +219,13 @@ public function install( $args, $assoc_args ) { WP_CLI::error( 'Only a single language can be active.' ); } - if ( empty( $assoc_args['format'] ) ) { - $assoc_args['format'] = 'table'; - } + $has_format_flag = isset( $assoc_args['format'] ); - if ( in_array( $assoc_args['format'], array( 'json', 'csv' ), true ) ) { - $logger = new \WP_CLI\Loggers\Quiet(); - \WP_CLI::set_logger( $logger ); + if ( $has_format_flag ) { + if ( in_array( $assoc_args['format'], array( 'json', 'csv' ), true ) ) { + $logger = new \WP_CLI\Loggers\Quiet(); + \WP_CLI::set_logger( $logger ); + } } $available = $this->get_installed_languages(); @@ -242,7 +242,9 @@ public function install( $args, $assoc_args ) { if ( in_array( $language_code, $available, true ) ) { \WP_CLI::log( "Language '{$language_code}' already installed." ); - $result['status'] = 'already installed'; + if ( $has_format_flag ) { + $result['status'] = 'already installed'; + } ++$skips; } else { $response = $this->download_language_pack( $language_code ); @@ -253,15 +255,21 @@ public function install( $args, $assoc_args ) { // Skip if translation is not yet available. if ( 'not_found' === $response->get_error_code() ) { - $result['status'] = 'not available'; + if ( $has_format_flag ) { + $result['status'] = 'not available'; + } ++$skips; } else { - $result['status'] = 'not installed'; + if ( $has_format_flag ) { + $result['status'] = 'not installed'; + } ++$errors; } } else { \WP_CLI::log( "Language '{$language_code}' installed." ); - $result['status'] = 'installed'; + if ( $has_format_flag ) { + $result['status'] = 'installed'; + } ++$successes; } } @@ -270,11 +278,19 @@ public function install( $args, $assoc_args ) { $this->activate_language( $language_code ); } - $results[] = (object) $result; + if ( $has_format_flag ) { + $results[] = (object) $result; + } } - if ( 'summary' !== $assoc_args['format'] ) { - \WP_CLI\Utils\format_items( $assoc_args['format'], $results, array( 'locale', 'status' ) ); + if ( $has_format_flag ) { + if ( empty( $assoc_args['format'] ) ) { + $assoc_args['format'] = 'table'; + } + + if ( 'summary' !== $assoc_args['format'] ) { + \WP_CLI\Utils\format_items( $assoc_args['format'], $results, array( 'locale', 'status' ) ); + } } \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); From 05894a36bfdcf239c03b1e69ab5bb40e76401cf2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 12:54:33 +0000 Subject: [PATCH 5/6] Remove default value from --format parameter to prevent auto-population WP-CLI's parameter parser uses the 'default' value in docblocks to automatically populate parameters. Removing 'default: table' ensures --format is only set when explicitly provided by the user, preserving backward compatibility with existing commands that don't use --format. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Language_Command.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index d207ed35..ceb75cdc 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -186,7 +186,6 @@ public function is_installed( $args ) { * [--format=] * : Render output in a particular format. Used when installing multiple languages. * --- - * default: table * options: * - table * - csv From 569ffc8282ef8bc154f26004a7dda7cd7975c908 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 12:55:23 +0000 Subject: [PATCH 6/6] Simplify format handling by removing unnecessary empty check Since WP-CLI validates format parameter values, there's no need to check for empty values and set a default. The format value will always be valid when isset() returns true. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Language_Command.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index ceb75cdc..7f004678 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -283,10 +283,6 @@ public function install( $args, $assoc_args ) { } if ( $has_format_flag ) { - if ( empty( $assoc_args['format'] ) ) { - $assoc_args['format'] = 'table'; - } - if ( 'summary' !== $assoc_args['format'] ) { \WP_CLI\Utils\format_items( $assoc_args['format'], $results, array( 'locale', 'status' ) ); }