Skip to content

Commit f23bae8

Browse files
authored
Merge pull request #170 from wp-cli/copilot/add-format-flag-to-update-commands
Add `--format` flag to language update commands
2 parents a4274d1 + d5e931b commit f23bae8

File tree

7 files changed

+394
-23
lines changed

7 files changed

+394
-23
lines changed

features/language-core.feature

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,77 @@ Feature: Manage core translation files for a WordPress install
477477
| nl_NL | installed |
478478
And STDERR should be empty
479479

480+
@require-wp-4.0
481+
Scenario: Core translation update with format flag
482+
Given a WP install
483+
And an empty cache
484+
485+
When I run `wp language core update --format=json`
486+
Then STDOUT should be:
487+
"""
488+
[]
489+
"""
490+
And STDERR should be empty
491+
492+
When I run `wp language core update --format=csv`
493+
Then STDOUT should be empty
494+
And STDERR should be empty
495+
496+
When I run `wp language core update --format=summary`
497+
Then STDOUT should contain:
498+
"""
499+
Success: Translations are up to date.
500+
"""
501+
And STDERR should be empty
502+
503+
@require-wp-6.0 @require-php-7.2
504+
Scenario Outline: Core translation update with dry-run and format flag
505+
Given an empty directory
506+
And WP files
507+
And a database
508+
And I run `wp core download --version=<original> --force`
509+
And wp-config.php
510+
And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
511+
512+
When I run `wp language core install en_CA ja`
513+
Then STDERR should be empty
514+
515+
Given I try `wp core download --version=<update> --force`
516+
Then the return code should be 0
517+
And I run `wp core update-db`
518+
519+
When I run `wp language core list --fields=language,status,update`
520+
Then STDOUT should be a table containing rows:
521+
| language | status | update |
522+
| en_CA | installed | available |
523+
| ja | installed | available |
524+
525+
When I run `wp language core update --dry-run --format=json`
526+
Then STDOUT should be JSON containing:
527+
"""
528+
[{"Type":"Core","Name":"WordPress","Version":"<update>"}]
529+
"""
530+
And STDERR should be empty
531+
532+
When I run `wp language core update --dry-run --format=csv`
533+
Then STDOUT should contain:
534+
"""
535+
Type,Name,Version,Language
536+
"""
537+
And STDOUT should contain:
538+
"""
539+
Core,WordPress,<update>
540+
"""
541+
And STDERR should be empty
542+
543+
When I run `wp language core update --dry-run --format=summary`
544+
Then STDOUT should be empty
545+
And STDERR should be empty
546+
547+
Examples:
548+
| original | update |
549+
| 6.5 | 6.6 |
550+
480551
@require-wp-4.0
481552
Scenario: Install languages with different output formats
482553
Given a WP install

features/language-plugin.feature

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,119 @@ Feature: Manage plugin translation files for a WordPress install
443443
And STDERR should be empty
444444

445445
@require-wp-4.0
446+
Scenario: Plugin translation update with format flag
447+
Given a WP install
448+
449+
When I run `wp plugin install hello-dolly --force`
450+
Then STDERR should be empty
451+
452+
When I run `wp language plugin update hello-dolly --format=json`
453+
Then STDOUT should be:
454+
"""
455+
[]
456+
"""
457+
And STDERR should be empty
458+
459+
When I run `wp language plugin update --all --format=csv`
460+
Then STDOUT should be empty
461+
And STDERR should be empty
462+
463+
When I run `wp language plugin update --all --format=summary`
464+
Then STDOUT should contain:
465+
"""
466+
Success: Translations are up to date.
467+
"""
468+
And STDERR should be empty
469+
470+
@require-wp-4.0
471+
Scenario: Plugin translation update with format flag and actual updates
472+
Given a WP install
473+
And an empty cache
474+
475+
When I run `wp plugin install akismet --version=3.2 --force`
476+
Then STDERR should be empty
477+
478+
When I run `wp language plugin install akismet de_DE`
479+
Then STDERR should be empty
480+
481+
When I run `wp plugin install akismet --version=4.0 --force`
482+
And I run `wp language plugin list akismet --fields=plugin,language,update,status`
483+
Then STDOUT should be a table containing rows:
484+
| plugin | language | update | status |
485+
| akismet | de_DE | available | installed |
486+
487+
When I run `wp language plugin update akismet --format=json`
488+
Then STDOUT should be JSON containing:
489+
"""
490+
[{"slug":"akismet","language":"de_DE","status":"updated"}]
491+
"""
492+
And STDERR should be empty
493+
494+
When I run `wp language plugin uninstall akismet de_DE`
495+
And I run `wp plugin install akismet --version=3.2 --force`
496+
And I run `wp language plugin install akismet de_DE`
497+
And I run `wp plugin install akismet --version=4.0 --force`
498+
And I run `wp language plugin update akismet --format=csv`
499+
Then STDOUT should contain:
500+
"""
501+
slug,language,status
502+
"""
503+
And STDOUT should contain:
504+
"""
505+
akismet,de_DE,updated
506+
"""
507+
And STDERR should be empty
508+
509+
When I run `wp language plugin uninstall akismet de_DE`
510+
And I run `wp plugin install akismet --version=3.2 --force`
511+
And I run `wp language plugin install akismet de_DE`
512+
And I run `wp plugin install akismet --version=4.0 --force`
513+
And I run `wp language plugin update akismet --format=summary`
514+
Then STDOUT should contain:
515+
"""
516+
Success: Updated 1/1 translation.
517+
"""
518+
And STDERR should be empty
519+
520+
@require-wp-4.0
521+
Scenario: Plugin translation update with dry-run and format flag
522+
Given a WP install
523+
And an empty cache
524+
525+
When I run `wp plugin install akismet --version=3.2 --force`
526+
Then STDERR should be empty
527+
528+
When I run `wp language plugin install akismet de_DE`
529+
Then STDERR should be empty
530+
531+
When I run `wp plugin install akismet --version=4.0 --force`
532+
And I run `wp language plugin list akismet --fields=plugin,language,update,status`
533+
Then STDOUT should be a table containing rows:
534+
| plugin | language | update | status |
535+
| akismet | de_DE | available | installed |
536+
537+
When I run `wp language plugin update akismet --dry-run --format=json`
538+
Then STDOUT should contain:
539+
"""
540+
"Type":"Plugin"
541+
"""
542+
And STDERR should be empty
543+
544+
When I run `wp language plugin update akismet --dry-run --format=csv`
545+
Then STDOUT should contain:
546+
"""
547+
Type,Name,Version,Language
548+
"""
549+
And STDOUT should contain:
550+
"""
551+
Plugin,"Akismet
552+
"""
553+
And STDERR should be empty
554+
555+
When I run `wp language plugin update akismet --dry-run --format=summary`
556+
Then STDOUT should be empty
557+
And STDERR should be empty
558+
446559
Scenario: Handle plugins with text domain different from slug
447560
Given a WP install
448561
And an empty cache

features/language-theme.feature

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,119 @@ Feature: Manage theme translation files for a WordPress install
327327
And STDERR should be empty
328328

329329
@require-wp-4.0
330+
Scenario: Theme translation update with format flag
331+
Given a WP install
332+
333+
When I try `wp theme install twentyten`
334+
Then STDOUT should not be empty
335+
336+
When I run `wp language theme update twentyten --format=json`
337+
Then STDOUT should be:
338+
"""
339+
[]
340+
"""
341+
And STDERR should be empty
342+
343+
When I run `wp language theme update --all --format=csv`
344+
Then STDOUT should be empty
345+
And STDERR should be empty
346+
347+
When I run `wp language theme update --all --format=summary`
348+
Then STDOUT should contain:
349+
"""
350+
Success: Translations are up to date.
351+
"""
352+
And STDERR should be empty
353+
354+
@require-wp-4.0
355+
Scenario: Theme translation update with format flag and actual updates
356+
Given a WP install
357+
And an empty cache
358+
359+
When I run `wp theme install twentyfifteen --version=2.0 --force`
360+
Then STDERR should be empty
361+
362+
When I run `wp language theme install twentyfifteen de_DE`
363+
Then STDERR should be empty
364+
365+
When I run `wp theme install twentyfifteen --version=2.5 --force`
366+
And I run `wp language theme list twentyfifteen --fields=theme,language,update,status`
367+
Then STDOUT should be a table containing rows:
368+
| theme | language | update | status |
369+
| twentyfifteen | de_DE | available | installed |
370+
371+
When I run `wp language theme update twentyfifteen --format=json`
372+
Then STDOUT should be JSON containing:
373+
"""
374+
[{"slug":"twentyfifteen","language":"de_DE","status":"updated"}]
375+
"""
376+
And STDERR should be empty
377+
378+
When I run `wp language theme uninstall twentyfifteen de_DE`
379+
And I run `wp theme install twentyfifteen --version=2.0 --force`
380+
And I run `wp language theme install twentyfifteen de_DE`
381+
And I run `wp theme install twentyfifteen --version=2.5 --force`
382+
And I run `wp language theme update twentyfifteen --format=csv`
383+
Then STDOUT should contain:
384+
"""
385+
slug,language,status
386+
"""
387+
And STDOUT should contain:
388+
"""
389+
twentyfifteen,de_DE,updated
390+
"""
391+
And STDERR should be empty
392+
393+
When I run `wp language theme uninstall twentyfifteen de_DE`
394+
And I run `wp theme install twentyfifteen --version=2.0 --force`
395+
And I run `wp language theme install twentyfifteen de_DE`
396+
And I run `wp theme install twentyfifteen --version=2.5 --force`
397+
And I run `wp language theme update twentyfifteen --format=summary`
398+
Then STDOUT should contain:
399+
"""
400+
Success: Updated 1/1 translation.
401+
"""
402+
And STDERR should be empty
403+
404+
@require-wp-4.0
405+
Scenario: Theme translation update with dry-run and format flag
406+
Given a WP install
407+
And an empty cache
408+
409+
When I run `wp theme install twentyfifteen --version=2.0 --force`
410+
Then STDERR should be empty
411+
412+
When I run `wp language theme install twentyfifteen de_DE`
413+
Then STDERR should be empty
414+
415+
When I run `wp theme install twentyfifteen --version=2.5 --force`
416+
And I run `wp language theme list twentyfifteen --fields=theme,language,update,status`
417+
Then STDOUT should be a table containing rows:
418+
| theme | language | update | status |
419+
| twentyfifteen | de_DE | available | installed |
420+
421+
When I run `wp language theme update twentyfifteen --dry-run --format=json`
422+
Then STDOUT should be JSON containing:
423+
"""
424+
[{"Type":"Theme","Name":"Twenty Fifteen"}]
425+
"""
426+
And STDERR should be empty
427+
428+
When I run `wp language theme update twentyfifteen --dry-run --format=csv`
429+
Then STDOUT should contain:
430+
"""
431+
Type,Name,Version,Language
432+
"""
433+
And STDOUT should contain:
434+
"""
435+
Theme,"Twenty Fifteen"
436+
"""
437+
And STDERR should be empty
438+
439+
When I run `wp language theme update twentyfifteen --dry-run --format=summary`
440+
Then STDOUT should be empty
441+
And STDERR should be empty
442+
330443
Scenario: Handle themes with text domain different from slug
331444
Given a WP install
332445
And an empty cache

src/Core_Language_Command.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ public function uninstall( $args ) {
389389
* [--dry-run]
390390
* : Preview which translations would be updated.
391391
*
392+
* [--format=<format>]
393+
* : Render output in a particular format. When not specified, updates show
394+
* progress messages and success/warning/error messages. When specified,
395+
* the output format changes based on the selected format.
396+
* ---
397+
* options:
398+
* - table
399+
* - csv
400+
* - json
401+
* - summary
402+
* ---
403+
*
392404
* ## EXAMPLES
393405
*
394406
* # Update installed core languages packs.
@@ -401,7 +413,7 @@ public function uninstall( $args ) {
401413
* @subcommand update
402414
*
403415
* @param string[] $args Positional arguments.
404-
* @param array{'dry-run'?: bool} $assoc_args Associative arguments.
416+
* @param array{'dry-run'?: bool, format?: string} $assoc_args Associative arguments.
405417
*/
406418
public function update( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found -- Overruling the documentation, so not useless ;-).
407419
parent::update( $args, $assoc_args );

src/Plugin_Language_Command.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,18 @@ public function uninstall( $args, $assoc_args ) {
591591
* [--dry-run]
592592
* : Preview which translations would be updated.
593593
*
594+
* [--format=<format>]
595+
* : Render output in a particular format. When not specified, updates show
596+
* progress messages and success/warning/error messages. When specified,
597+
* the output format changes based on the selected format.
598+
* ---
599+
* options:
600+
* - table
601+
* - csv
602+
* - json
603+
* - summary
604+
* ---
605+
*
594606
* ## EXAMPLES
595607
*
596608
* # Update all installed language packs for all plugins.
@@ -603,7 +615,7 @@ public function uninstall( $args, $assoc_args ) {
603615
* @subcommand update
604616
*
605617
* @param string[] $args Positional arguments.
606-
* @param array{'dry-run'?: bool, all?: bool} $assoc_args Associative arguments.
618+
* @param array{'dry-run'?: bool, all?: bool, format?: string} $assoc_args Associative arguments.
607619
*/
608620
public function update( $args, $assoc_args ) {
609621
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );

0 commit comments

Comments
 (0)