Skip to content

Add --format flag to language update commands#170

Merged
swissspidy merged 32 commits intomainfrom
copilot/add-format-flag-to-update-commands
Feb 16, 2026
Merged

Add --format flag to language update commands#170
swissspidy merged 32 commits intomainfrom
copilot/add-format-flag-to-update-commands

Conversation

Copy link
Contributor

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 - Display results in table format with formatted output 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 (no output in dry-run mode)
  • No format specified - Display progress messages and success/warning/error messages (default behavior)

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 with json/csv: output only formatted data
    • For dry-run with table/no format: show message and table
    • For dry-run with summary: produce no output
    • 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, clarifying behavior when format is not specified

  3. Plugin_Language_Command.php: Added --format parameter documentation to the update command docblock, clarifying behavior when format is not specified

  4. Theme_Language_Command.php: Added --format parameter documentation to the update command docblock, clarifying behavior when format is not specified

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

Tests with dry-run and format flags:

  • Core test: Uses WordPress version upgrade to trigger available translations
  • Plugin test: Uses akismet with version upgrade to trigger available translations
  • Theme test: Uses twentyfifteen with version upgrade to trigger available translations
  • Tests verify JSON, CSV, and summary formats produce correct output in dry-run mode
  • JSON/CSV formats show only formatted data without messages
  • Summary format produces no output in dry-run mode
  • Table/no format shows message and table in dry-run mode

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/no format, suppressed for json/csv/summary
✅ Efficient data collection (skips when not needed for summary format)
✅ Correct output for empty results
✅ Works with both --dry-run and actual updates
✅ Comprehensive test coverage including dry-run with format flags

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
  • Added test scenarios for dry-run combined with format flags (json, csv, summary)
  • Fixed documentation to remove misleading "default: table" and clarify actual behavior when no format is specified
  • Fixed dry-run with summary format to produce no output (aligning code with test expectations)

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
@swissspidy

This comment was marked as resolved.

…ixtures

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

This comment was marked as resolved.

@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.

@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.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

- Add test scenarios for dry-run combined with format flags (json, csv, summary) for core, plugin, and theme language update commands
- Fix documentation to remove misleading "default: table" and clarify actual behavior when no format is specified
- When no format is specified, commands show progress messages and success/warning/error messages without formatted table output
- This addresses the missing test coverage identified in code review

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

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

The logic for handling --dry-run with --format=summary was incorrect. It was outputting the message and table, but the tests expect empty output. Fixed the condition to:
- json/csv formats: output formatted data only
- table or no format: output message and table
- summary format: no output (as per test expectations)

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

This comment was marked as resolved.

@swissspidy swissspidy added this to the 2.0.26 milestone Feb 12, 2026
@swissspidy swissspidy merged commit f23bae8 into main Feb 16, 2026
60 checks passed
@swissspidy swissspidy deleted the copilot/add-format-flag-to-update-commands branch February 16, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:language-core-update Related to 'language core update' command command:language-plugin-update Related to 'language plugin update' command command:language-theme-update Related to 'language theme update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants