Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json and csv formats to upgrade output #2452

Merged
merged 7 commits into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions features/theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,57 @@ Feature: Manage WordPress themes
| name | status |
| biker | active |
| jolene | parent |

Scenario: When updating a theme --format should be the same when using --dry-run
Given a WP install

When I run `wp theme install --force twentytwelve --version=1.0`
Then STDOUT should not be empty

When I run `wp theme list --name=twentytwelve --field=update_version`
And save STDOUT as {UPDATE_VERSION}

When I run `wp theme update twentytwelve --format=summary --dry-run`
Then STDOUT should contain:
"""
Available theme updates:
Twenty Twelve update from version 1.0 to version {UPDATE_VERSION}
"""

When I run `wp theme update twentytwelve --format=json --dry-run`
Then STDOUT should be JSON containing:
"""
[{"name":"twentytwelve","status":"inactive","version":"1.0","update_version":"{UPDATE_VERSION}"}]
"""

When I run `wp theme update twentytwelve --format=csv --dry-run`
Then STDOUT should contain:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Then STDOUT should be CSV containing:

"""
name,status,version,update_version
twentytwelve,inactive,1.0,{UPDATE_VERSION}
"""

Scenario: Check json and csv formats when updating a theme
Given a WP install

When I run `wp theme install --force twentytwelve --version=1.0`
Then STDOUT should not be empty

When I run `wp theme list --name=twentytwelve --field=update_version`
And save STDOUT as {UPDATE_VERSION}

When I run `wp theme update twentytwelve --format=json`
Then STDOUT should contain:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

"""
[{"name":"twentytwelve","old_version":"1.0","new_version":"{UPDATE_VERSION}","status":"Updated"}]
"""

When I run `wp theme install --force twentytwelve --version=1.0`
Then STDOUT should not be empty

When I run `wp theme update twentytwelve --format=csv`
Then STDOUT should contain:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

"""
name,old_version,new_version,status
twentytwelve,1.0,{UPDATE_VERSION},Updated
"""
28 changes: 23 additions & 5 deletions php/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ protected function get_upgrader( $assoc_args ) {
protected function update_many( $args, $assoc_args ) {
call_user_func( $this->upgrade_refresh );

if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], array( 'json', 'csv' ) ) ) {
$logger = new \WP_CLI\Loggers\Quiet;
\WP_CLI::set_logger( $logger );
}

if ( ! \WP_CLI\Utils\get_flag_value( $assoc_args, 'all' ) && empty( $args ) ) {
\WP_CLI::error( "Please specify one or more {$this->item_type}s, or use --all." );
}
Expand All @@ -232,10 +237,17 @@ protected function update_many( $args, $assoc_args ) {
return;
}

\WP_CLI::line( "Available {$this->item_type} updates:" );

\WP_CLI\Utils\format_items( 'table', $items_to_update,
array( 'name', 'status', 'version', 'update_version' ) );
if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], array( 'json', 'csv' ) ) ) {
\WP_CLI\Utils\format_items( $assoc_args['format'], $items_to_update, array( 'name', 'status', 'version', 'update_version' ) );
} else if ( ! empty( $assoc_args['format'] ) && 'summary' === $assoc_args['format'] ) {
\WP_CLI::line( "Available {$this->item_type} updates:" );
foreach( $items_to_update as $item_to_update => $info ) {
\WP_CLI::log( "{$info['title']} update from version {$info['version']} to version {$info['update_version']}" );
}
} else {
\WP_CLI::line( "Available {$this->item_type} updates:" );
\WP_CLI\Utils\format_items( 'table', $items_to_update, array( 'name', 'status', 'version', 'update_version' ) );
}

return;
}
Expand Down Expand Up @@ -282,7 +294,13 @@ protected function update_many( $args, $assoc_args ) {
'status' => $result[ $info['update_id'] ] !== null ? 'Updated' : 'Error',
);
}
\WP_CLI\Utils\format_items( 'table', $status, array( 'name', 'old_version', 'new_version', 'status' ) );

$format = 'table';
if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], array( 'json', 'csv' ) ) ) {
$format = $assoc_args['format'];
}

\WP_CLI\Utils\format_items( $format, $status, array( 'name', 'old_version', 'new_version', 'status' ) );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion php/WP_CLI/UpgraderSkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function feedback( $string ) {

$string = str_replace( '…', '...', strip_tags( $string ) );

\WP_CLI::line( $string );
\WP_CLI::log( $string );
}
}