Skip to content

Conversation

Copy link

Copilot AI commented Nov 2, 2025

Add --format Flag to Language Update Commands

This PR adds support for the --format flag to the language update commands, resolving the issue where the --json flag (which WP-CLI automatically converts to --format=json for backward compatibility) was generating errors.

Problem Statement

The issue reported that all update commands for language files with --json generate an error:

wp language core update --json
wp language plugin update --all --json
wp language theme update --all --json

This was because the update commands didn't support the --format flag, even though WP-CLI was converting --json to --format=json automatically.

Solution

Added --format flag support to:

  • wp language core update
  • wp language plugin update
  • wp language theme update

Supported Formats

  • table (default) - Display results in table format with progress messages and success message
  • json - Display results as JSON (suppresses all messages)
  • csv - Display results as CSV (suppresses all messages)
  • summary - Display only summary message without formatted output

Implementation Details

Code Changes:

  1. CommandWithTranslation.php: Updated the update() method to:

    • Accept the --format parameter in the method signature
    • Set quiet logger for json/csv formats to suppress progress messages
    • Collect update results with appropriate keys (version for core, slug for plugins/themes)
    • Format output according to the specified format
    • Show success/warning/error messages for table, summary, or no format (default behavior)
    • Suppress success messages for json/csv formats
    • For dry-run: Show "Found X translation updates" message for table/summary/no format
    • For dry-run: Suppress message for json/csv formats
    • Use WP_CLI::log() instead of WP_CLI::line() for proper quiet logger support
  2. Core_Language_Command.php: Added --format parameter documentation to the update command docblock

  3. Plugin_Language_Command.php: Added --format parameter documentation to the update command docblock

  4. Theme_Language_Command.php: Added --format parameter documentation to the update command docblock

Test Coverage:

Added comprehensive Behat test scenarios for all three commands:

Tests with no updates:

  • --format=json outputs empty JSON array, no messages
  • --format=csv outputs nothing
  • --format=summary shows success message on STDOUT
  • No format (default) shows success message on STDOUT

Tests with actual updates:

  • Plugin test: Uses akismet with version downgrade/upgrade to trigger updates
  • Theme test: Uses twentyfifteen with version downgrade/upgrade to trigger updates
  • Tests verify JSON, CSV, and summary formats produce correct output
  • JSON format outputs array with slug/version, language, and status
  • CSV format outputs proper CSV with headers and data
  • Summary format only shows success message on STDOUT
  • Table format outputs formatted data with success message
  • Tests uninstall language before reinstalling to ensure update is triggered

Key Features:

✅ Backward compatibility with --json flag (automatically converted to --format=json)
✅ Consistent behavior with other language commands (install, uninstall, list)
✅ Proper quiet logger support for json/csv formats
✅ Success messages shown for table/summary formats or when no format is specified
✅ Dry-run message shown for table/summary/no format, suppressed for json/csv
✅ Efficient data collection (skips when not needed for summary format)
✅ Correct output for empty results
✅ Works with both --dry-run and actual updates

Changes from Feedback:

  • Success message is shown when format is 'table', 'summary', or when no format is specified
  • Success messages are suppressed only for json/csv formats
  • Updated tests to use standard fixtures (twentyten, hello-dolly) instead of custom test fixtures
  • Added comprehensive tests with actual translation updates to verify formatted output
  • Fixed test expectations to check STDOUT for success messages (not STDERR)
  • Removed invalid --force flag from language install commands in tests
  • Fixed linting issues: Changed "When" to "And" for subsequent steps
  • Aligned table columns in test expectations
  • Fixed format handling to treat 'table' format the same as default behavior
  • Uninstall language before reinstalling in tests to ensure updates are properly triggered
  • Fixed dry-run to show "Found X translation updates" message for table/summary formats
  • Fixed theme test to not expect empty STDERR when using When I try

The implementation is ready for review and testing in a live WP-CLI environment.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add --format flag to language core|plugin|theme update</issue_title>
<issue_description>grafik

All update commands for language files with "- json" generate an error.

wp language core update --dry-run --json
wp language plugin update --all --dry-run --json
wp language theme update --all --dry-run --json
wp language core update --json
wp language plugin update --all --json
wp language theme update --all --json

</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera There's two things happening here: a.) `--json` is a deprecated flag that was later replaced by the more generic `--format=json`, as we also support other formats by now. WP-CLI automatically turns `--json` into `--format=json` for backward compatibility. b.) The above three commands don't support a `--format` flag, so the error just tells you that you're using an unknown flag for these commands.

So the behavior of WP-CLI is correct here, even if it might be slightly misleading due to backward compatibility logic.

As to whether we would want to add --format support to these commands, it would help to know what specific use case you are trying to solve.</comment_new>
<comment_new>@schlessera
It is not a current priority.

Are you interested in looking into this for creating a PR? If so, I'm happy to assist you in whatever way I can to get this implemented.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 2, 2025
Copilot AI and others added 7 commits November 2, 2025 17:12
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add --format flag to language update commands Add --format flag to language update commands Nov 2, 2025
Copilot AI requested a review from swissspidy November 2, 2025 17:31
Copilot finished work on behalf of swissspidy November 2, 2025 17:31
@swissspidy

This comment was marked as resolved.

…ixtures

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot finished work on behalf of swissspidy November 3, 2025 08:35
@swissspidy

This comment was marked as resolved.

…l updates

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot finished work on behalf of swissspidy November 3, 2025 08:56
@swissspidy

This comment was marked as resolved.

…nstall commands

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot finished work on behalf of swissspidy November 3, 2025 09:46
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot finished work on behalf of swissspidy November 3, 2025 12:37
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot finished work on behalf of swissspidy November 3, 2025 13:11
@swissspidy

This comment was marked as resolved.

…theme test

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/WP_CLI/CommandWithTranslation.php 88.88% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy changed the title Add --format flag to language update commands Add --format flag to language update commands Nov 3, 2025
@swissspidy swissspidy marked this pull request as ready for review November 3, 2025 20:57
@swissspidy swissspidy requested a review from a team as a code owner November 3, 2025 20:57
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.

Add --format flag to language core|plugin|theme update

2 participants