Skip to content

Add --all flag for plugin uninstall command#84

Merged
schlessera merged 12 commits intowp-cli:masterfrom
BhargavBhandari90:GH-75
Feb 25, 2018
Merged

Add --all flag for plugin uninstall command#84
schlessera merged 12 commits intowp-cli:masterfrom
BhargavBhandari90:GH-75

Conversation

@BhargavBhandari90
Copy link
Contributor

@BhargavBhandari90 BhargavBhandari90 commented Feb 12, 2018

for #75

@BhargavBhandari90 BhargavBhandari90 changed the title WIP: #75Add --all flag for plugin uninstall command WIP: #75 Add --all flag for plugin uninstall command Feb 12, 2018
@BhargavBhandari90 BhargavBhandari90 changed the title WIP: #75 Add --all flag for plugin uninstall command Add --all flag for plugin uninstall command Feb 12, 2018
@BhargavBhandari90
Copy link
Contributor Author

@schlessera @danielbachhuber

I think the test is not failing because of my changes.

It's showing error from features/plugin-install.feature and features/upgradables.feature which is not changed.

* will be run.
*
* [--all]
* : If set, all deactive plugins will be uninstalled.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need deactive, as the --deactivate option covers that.

Then STDOUT should be:
"""
Uninstalled and deleted 'akismet' plugin.
Uninstalled and deleted 'hello.php' plugin.
Copy link
Contributor

Choose a reason for hiding this comment

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

This will change to 'hello' - see below re using check_optional_args_and_all().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's giving me error in testing if I make it hello.

"""
And the return code should be 0

Scenario: Uninstall all installed plugin
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo 'plugin' -> 'plugins'.

Uninstalled and deleted 'hello.php' plugin.
Success: Uninstalled 2 of 2 plugins.
"""
And the return code should be 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Also should maybe do When I run the previous command again step here with STDOUT Success: No plugins installed..

Also add scenario Uninstall all installed plugins when one or more activated with one plugin activated and run without and with --deactivate flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gitlost I am having some problem with this test. Can you please check.

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

// If get all parameter from command, then uninstall all deactive plugins.
if ( $all ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So this block goes.

}
if ( ! $this->chained_command ) {
Utils\report_batch_operation_results( 'plugin', 'uninstall', count( $args ), $successes, $errors );
Utils\report_batch_operation_results( 'plugin', 'uninstall', count( $plugins ), $successes, $errors );
Copy link
Contributor

Choose a reason for hiding this comment

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

And this change isn't needed (if the if ( count( $plugins ) < count( $args ) ) { logic above is put in).

$successes = $errors = 0;

$all = Utils\get_flag_value( $assoc_args, 'all', false );

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you do

		if ( ! ( $args = $this->check_optional_args_and_all( $args, $all ) ) ) {
			return;
		}

here. This will mean the if ( $all ) { block isn't needed.

$all = Utils\get_flag_value( $assoc_args, 'all', false );

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, the other --all commands do this logic after fetching:

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

which looks like it should be done here too but causes for instance features/plugin-uninstall.feature:28 to fail with Error: No plugins uninstalled. instead of succeeding with Success: Plugin already uninstalled.. And also the final step of features/plugin.feature:3. So this would be a BC break. But maybe the right thing to do anyway...

@gitlost gitlost added the command:plugin-uninstall Related to 'plugin uninstall' command label Feb 13, 2018
@gitlost gitlost added this to the 1.1.10 milestone Feb 13, 2018
@gitlost
Copy link
Contributor

gitlost commented Feb 13, 2018

Ah, so you have to do your review comments in code order, not very second-thoughts friendly...

@BhargavBhandari90
Copy link
Contributor Author

@gitlost See this.
screen shot 2018-02-15 at 5 34 01 pm

@schlessera
Copy link
Member

@BhargavBhandari90 When you run a test that expects an error to be thrown, like it is the case here, you need to use And I try ..., not And I run ....
run => expect successful result
try => expect error

}

// If get all parameter from command, then uninstall all deactive plugins.
if ( $all ) {
Copy link
Contributor

@gitlost gitlost Feb 15, 2018

Choose a reason for hiding this comment

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

This block should be removed as it isn't needed after setting the args with check_optional_args_and_all().

This will then change the name of hello.php to hello.

"""
Success: Activated 2 of 2 plugins.
"""
And I run `wp plugin uninstall --all`
Copy link
Contributor

Choose a reason for hiding this comment

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

As @schlessera mentioned need this to be When I try as it will fail without the --deactivate flag. Then have another successful step with the --deactivate flag.

@gitlost
Copy link
Contributor

gitlost commented Feb 15, 2018

The other failures happening are due to the BC break and are mentioned here #84 (comment). So those tests will have to be adjusted (assuming everyone's ok with the BC break).


Scenario: Attempting to uninstall a plugin that doesn't exist
When I try `wp plugin uninstall edit-flow`
And STDERR should be:
Copy link
Member

Choose a reason for hiding this comment

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

And => Then

When I run the previous command again
Then STDOUT should be:
"""
Success: No plugins installed.
Copy link
Member

Choose a reason for hiding this comment

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

No plugins installed => No plugins uninstalled

Copy link
Member

Choose a reason for hiding this comment

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

This will require a change to the check_args_and_all() method, as the installed is currently hardcoded in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@schlessera I did little different for this. Let me know if this solution is good or not.

"""

Scenario: Uninstall all installed plugins when one or more activated
And I run `wp plugin activate --all`
Copy link
Member

Choose a reason for hiding this comment

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

And => When

"""
Success: Activated 2 of 2 plugins.
"""
And I try `wp plugin uninstall --all`
Copy link
Member

Choose a reason for hiding this comment

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

And => new line + When

Success: Activated 2 of 2 plugins.
"""
And I try `wp plugin uninstall --all`
And STDERR should be:
Copy link
Member

Choose a reason for hiding this comment

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

And => Then

Error: No plugins uninstalled.
"""
And the return code should be 1
And I run `wp plugin uninstall --deactivate --all`
Copy link
Member

Choose a reason for hiding this comment

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

And => new line + When

@schlessera
Copy link
Member

@BhargavBhandari90 I've added a few change requests.

For the basic tests setup, it should always read like normal sentences:

When ___
Then ___
And ___
[ And ___ ]
[ And ___ ]
...

When ___
Then ___
And ___
[ And ___ ]
[ And ___ ]
...

@BhargavBhandari90
Copy link
Contributor Author

@schlessera, Done with the changes. Please review.

@schlessera schlessera merged commit a4a2553 into wp-cli:master Feb 25, 2018
@schlessera
Copy link
Member

Thanks for the PR, @BhargavBhandari90 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:plugin-uninstall Related to 'plugin uninstall' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants