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 --all flag to plugin delete #103

Merged
merged 3 commits into from Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions features/plugin-delete.feature
Expand Up @@ -12,6 +12,22 @@ Feature: Delete WordPress plugins
"""
And the return code should be 0

Scenario: Delete all installed plugins
When I run `wp plugin delete --all`
Then STDOUT should be:
"""
Deleted 'akismet' plugin.
Deleted 'hello' plugin.
Success: Deleted 2 of 2 plugins.
"""
And the return code should be 0

When I run the previous command again
Then STDOUT should be:
"""
Success: No plugins deleted.
"""

Scenario: Attempting to delete a plugin that doesn't exist
When I try `wp plugin delete edit-flow`
Then STDOUT should be:
Expand Down
18 changes: 17 additions & 1 deletion src/Plugin_Command.php
Expand Up @@ -936,8 +936,11 @@ public function is_active( $args, $assoc_args = array() ) {
*
* ## OPTIONS
*
* <plugin>...
* [<plugin>...]
* : One or more plugins to delete.
*
* [--all]
* : If set, all plugins will be deleted.
*
* ## EXAMPLES
*
Expand All @@ -952,7 +955,20 @@ public function is_active( $args, $assoc_args = array() ) {
* Success: Deleted 1 of 1 plugins.
*/
public function delete( $args, $assoc_args = array() ) {
$all = Utils\get_flag_value( $assoc_args, 'all', false );

// Check if plugin names of --all is passed.
if ( ! ( $args = $this->check_optional_args_and_all( $args, $all, 'delete' ) ) ) {
return;
}

$successes = $errors = 0;

$plugins = $this->fetcher->get_many( $args );
Copy link
Member

Choose a reason for hiding this comment

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

Lines 967-970 are not needed, this is already covered by the code immediately following.

Just removing these should fix the broken tests.

if ( count( $plugins ) < count( $args ) ) {
$errors = count( $args ) - count( $plugins );
}

foreach ( $this->fetcher->get_many( $args ) as $plugin ) {
if ( $this->_delete( $plugin ) ) {
WP_CLI::log( "Deleted '{$plugin->name}' plugin." );
Expand Down