Skip to content

Commit a4a2553

Browse files
authored
Merge pull request #84 from BhargavBhandari90/GH-75
Add --all flag for plugin uninstall command
2 parents 5a4bfac + d197330 commit a4a2553

File tree

3 files changed

+71
-18
lines changed

3 files changed

+71
-18
lines changed

features/plugin-uninstall.feature

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,47 @@ Feature: Uninstall a WordPress plugin
2727

2828
Scenario: Attempting to uninstall a plugin that doesn't exist
2929
When I try `wp plugin uninstall edit-flow`
30-
Then STDOUT should be:
30+
Then STDERR should be:
3131
"""
32-
Success: Plugin already uninstalled.
32+
Warning: The 'edit-flow' plugin could not be found.
33+
Error: No plugins uninstalled.
3334
"""
34-
And STDERR should be:
35+
And the return code should be 1
36+
37+
Scenario: Uninstall all installed plugins
38+
When I run `wp plugin uninstall --all`
39+
Then STDOUT should be:
3540
"""
36-
Warning: The 'edit-flow' plugin could not be found.
41+
Uninstalled and deleted 'akismet' plugin.
42+
Uninstalled and deleted 'hello' plugin.
43+
Success: Uninstalled 2 of 2 plugins.
3744
"""
3845
And the return code should be 0
46+
47+
When I run the previous command again
48+
Then STDOUT should be:
49+
"""
50+
Success: No plugins uninstalled.
51+
"""
52+
53+
Scenario: Uninstall all installed plugins when one or more activated
54+
When I run `wp plugin activate --all`
55+
Then STDOUT should contain:
56+
"""
57+
Success: Activated 2 of 2 plugins.
58+
"""
59+
60+
When I try `wp plugin uninstall --all`
61+
Then STDERR should be:
62+
"""
63+
Warning: The 'akismet' plugin is active.
64+
Warning: The 'hello' plugin is active.
65+
Error: No plugins uninstalled.
66+
"""
67+
And the return code should be 1
68+
69+
When I run `wp plugin uninstall --deactivate --all`
70+
Then STDOUT should contain:
71+
"""
72+
Success: Uninstalled 2 of 2 plugins.
73+
"""

features/plugin.feature

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,11 @@ Feature: Manage WordPress plugins
6767
| Zombieland | active | none | 0.1.0 |
6868

6969
When I try `wp plugin uninstall Zombieland`
70-
Then STDERR should contain:
71-
"""
72-
The 'Zombieland' plugin is active.
73-
"""
74-
And STDERR should contain:
70+
Then STDERR should be:
7571
"""
72+
Warning: The 'Zombieland' plugin is active.
7673
Error: No plugins uninstalled.
7774
"""
78-
And STDOUT should be empty
7975
And the return code should be 1
8076

8177
When I run `wp plugin deactivate Zombieland`
@@ -96,15 +92,20 @@ Feature: Manage WordPress plugins
9692
And the {PLUGIN_DIR}/zombieland file should not exist
9793

9894
When I try the previous command again
99-
Then STDERR should be:
95+
Then STDERR should contain:
10096
"""
101-
Warning: The 'Zombieland' plugin could not be found.
97+
Warning:
10298
"""
103-
And STDOUT should be:
99+
And STDERR should contain:
104100
"""
105-
Success: Plugin already uninstalled.
101+
Zombieland
106102
"""
107-
And the return code should be 0
103+
And STDERR should contain:
104+
"""
105+
Error: No plugins uninstalled.
106+
"""
107+
And STDOUT should be empty
108+
And the return code should be 1
108109

109110
Scenario: Install a plugin, activate, then force install an older version of the plugin
110111
Given a WP install

src/Plugin_Command.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ public function get( $args, $assoc_args ) {
810810
*
811811
* ## OPTIONS
812812
*
813-
* <plugin>...
813+
* [<plugin>...]
814814
* : One or more plugins to uninstall.
815815
*
816816
* [--deactivate]
@@ -820,15 +820,30 @@ public function get( $args, $assoc_args ) {
820820
* : If set, the plugin files will not be deleted. Only the uninstall procedure
821821
* will be run.
822822
*
823+
* [--all]
824+
* : If set, all plugins will be uninstalled.
825+
*
823826
* ## EXAMPLES
824827
*
825828
* $ wp plugin uninstall hello
826829
* Uninstalled and deleted 'hello' plugin.
827830
* Success: Installed 1 of 1 plugins.
828831
*/
829832
public function uninstall( $args, $assoc_args = array() ) {
833+
834+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
835+
836+
// Check if plugin names of --all is passed.
837+
if ( ! ( $args = $this->check_optional_args_and_all( $args, $all, 'uninstall' ) ) ) {
838+
return;
839+
}
840+
830841
$successes = $errors = 0;
831842
$plugins = $this->fetcher->get_many( $args );
843+
if ( count( $plugins ) < count( $args ) ) {
844+
$errors = count( $args ) - count( $plugins );
845+
}
846+
832847
foreach ( $plugins as $plugin ) {
833848
if ( is_plugin_active( $plugin->file ) && ! WP_CLI\Utils\get_flag_value( $assoc_args, 'deactivate' ) ) {
834849
WP_CLI::warning( "The '{$plugin->name}' plugin is active." );
@@ -1082,7 +1097,7 @@ private function get_all_plugins() {
10821097
* @param bool $all All flag.
10831098
* @return array Same as $args if not all, otherwise all slugs.
10841099
*/
1085-
private function check_optional_args_and_all( $args, $all ) {
1100+
private function check_optional_args_and_all( $args, $all, $verb = 'install' ) {
10861101
if ( $all ) {
10871102
$args = array_map( function( $file ){
10881103
return Utils\get_plugin_name( $file );
@@ -1093,7 +1108,9 @@ private function check_optional_args_and_all( $args, $all ) {
10931108
if ( ! $all ) {
10941109
WP_CLI::error( 'Please specify one or more plugins, or use --all.' );
10951110
}
1096-
WP_CLI::success( 'No plugins installed.' ); // Don't error if --all given for BC.
1111+
1112+
$past_tense_verb = Utils\past_tense_verb( $verb );
1113+
WP_CLI::success( "No plugins {$past_tense_verb}." ); // Don't error if --all given for BC.
10971114
}
10981115

10991116
return $args;

0 commit comments

Comments
 (0)