Skip to content
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
18 changes: 18 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.DS_Store
.git
.gitignore
.gitlab-ci.yml
.editorconfig
.travis.yml
behat.yml
circle.yml
phpcs.xml.dist
phpunit.xml.dist
bin/
features/
utils/
*.zip
*.tar.gz
*.swp
*.txt
*.log
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.claude export-ignore
/.editorconfig export-ignore
/.gherkin-lintrc export-ignore
/.github export-ignore
/.gitignore export-ignore
/behat.yml export-ignore
/features export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/wp-cli.yml export-ignore
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## 2.0.0 - 2026-08-18
- Added: `--yes` flag to skip the confirmation prompt
- Changed: require WP-CLI v3.0 or greater

## 1.0.0 - 2016-05-06
- Initial release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (C) 2026 Nilambar Sharma

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
61 changes: 52 additions & 9 deletions features/database-command-basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Feature: Basic tests

When I run `wp user create firstadmin firstadmin@gmail.com --role=administrator`
And I run `wp user create secondadmin secondadmin@gmail.com --role=administrator`
And I run `wp database reset --author=secondadmin`
And I run `wp database reset --author=secondadmin --yes`
And I run `wp user list --role=administrator --format=count`
Then STDOUT should be:
"""
Expand All @@ -62,7 +62,7 @@ Feature: Basic tests
Given a WP install

When I run `wp user create admin.name admin.name@gmail.com --role=administrator`
And I run `wp database reset --author=admin.name`
And I run `wp database reset --author=admin.name --yes`
Then STDOUT should contain:
"""
Success: Database is reset successfully.
Expand All @@ -80,7 +80,7 @@ Feature: Basic tests
"""

When I run `wp user create installfailadmin installfailadmin@gmail.com --role=administrator`
And I try `wp database reset --author=installfailadmin`
And I try `wp database reset --author=installfailadmin --yes`
Then STDERR should contain:
"""
Error: Reset failed
Expand All @@ -92,7 +92,7 @@ Feature: Basic tests
When I run `wp role create customadmin "Custom Admin"`
And I run `wp user create customadminuser customadminuser@gmail.com --role=customadmin`
And I run `wp eval 'get_role( "customadmin" )->add_cap( "manage_options" );'`
And I run `wp database reset --author=customadminuser`
And I run `wp database reset --author=customadminuser --yes`
Then STDOUT should contain:
"""
Success: Database is reset successfully.
Expand All @@ -102,8 +102,8 @@ Feature: Basic tests
Given a WP install

When I run `wp user create repeatadmin repeatadmin@gmail.com --role=administrator`
And I run `wp database reset --author=repeatadmin`
And I run `wp database reset --author=repeatadmin`
And I run `wp database reset --author=repeatadmin --yes`
And I run `wp database reset --author=repeatadmin --yes`
Then STDOUT should contain:
"""
Success: Database is reset successfully.
Expand Down Expand Up @@ -132,7 +132,7 @@ Feature: Basic tests
Given a WP install

When I run `wp user create testadmin testadmin@gmail.com --role=administrator`
And I run `wp database reset --author=testadmin`
And I run `wp database reset --author=testadmin --yes`
Then STDOUT should contain:
"""
Success: Database is reset successfully.
Expand All @@ -151,7 +151,7 @@ Feature: Basic tests
Given a WP install

When I run `wp user create spacedadmin spacedadmin@gmail.com --role=administrator`
And I run `wp database reset --author=" spacedadmin "`
And I run `wp database reset --author=" spacedadmin " --yes`
Then STDOUT should contain:
"""
Success: Database is reset successfully.
Expand All @@ -162,7 +162,7 @@ Feature: Basic tests
Given a WP install

When I run `wp user create caseadmin caseadmin@gmail.com --role=administrator`
And I run `wp database reset --author=CASEADMIN`
And I run `wp database reset --author=CASEADMIN --yes`
Then STDOUT should contain:
"""
Success: Database is reset successfully.
Expand Down Expand Up @@ -219,3 +219,46 @@ Feature: Basic tests
"""
--author
"""

Scenario: Test help shows yes parameter
Given an empty directory

When I try `PAGER= wp help database reset`
Then STDOUT should contain:
"""
--yes
"""

Scenario: Test reset prompts for confirmation when --yes is not passed
Given a WP install

When I run `wp user create noyesadmin noyesadmin@gmail.com --role=administrator`
And I run `wp database reset --author=noyesadmin`
Then STDOUT should contain:
"""
Are you sure you want to reset the database? [y/n]
"""
And STDOUT should not contain:
"""
Success: Database is reset successfully.
"""

When I run `wp user get noyesadmin --field=login`
Then STDOUT should be:
"""
noyesadmin
"""

Scenario: Test reset proceeds without prompting when --yes is passed
Given a WP install

When I run `wp user create yesadmin yesadmin@gmail.com --role=administrator`
And I run `wp database reset --author=yesadmin --yes`
Then STDOUT should not contain:
"""
[y/n]
"""
And STDOUT should contain:
"""
Success: Database is reset successfully.
"""
30 changes: 15 additions & 15 deletions features/database-command-reset.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Feature: Test reset behaviour
Given a WP install

When I run `wp user create testadmin2 testadmin2@gmail.com --role=administrator`
And I run `wp database reset --author=testadmin2`
And I run `wp database reset --author=testadmin2 --yes`
And I run `wp user list --role=administrator --format=count`
Then STDOUT should be:
"""
1
"""

When I run `wp user create testadmin3 testadmin3@gmail.com --role=administrator`
And I run `wp database reset --author=testadmin3`
And I run `wp database reset --author=testadmin3 --yes`
And I run `wp user get testadmin3 --field=email`
Then STDOUT should be:
"""
Expand All @@ -22,7 +22,7 @@ Feature: Test reset behaviour
When I run `wp user create testadmin4 testadmin4@gmail.com --role=administrator --user_pass=testpass@1234`
And I run `wp user get testadmin4 --field=user_pass`
And save STDOUT as {USER_PASS}
And I run `wp database reset --author=testadmin4`
And I run `wp database reset --author=testadmin4 --yes`
And I run `wp user get testadmin4 --field=user_pass`
Then STDOUT should be:
"""
Expand All @@ -31,7 +31,7 @@ Feature: Test reset behaviour

When I run `wp user create testadmin5 testadmin5@gmail.com --role=administrator`
And I run `wp post generate --count=10`
And I run `wp database reset --author=testadmin5`
And I run `wp database reset --author=testadmin5 --yes`
And I run `wp post list --format=count`
Then STDOUT should be:
"""
Expand All @@ -41,7 +41,7 @@ Feature: Test reset behaviour
When I run `wp user create testadmin6 testadmin6@gmail.com --role=administrator`
And I run `wp option get blogname`
And save STDOUT as {BLOG_NAME}
And I run `wp database reset --author=testadmin6`
And I run `wp database reset --author=testadmin6 --yes`
And I run `wp option get blogname`
Then STDOUT should be:
"""
Expand All @@ -50,7 +50,7 @@ Feature: Test reset behaviour

When I run `wp user create testadmin7 testadmin7@gmail.com --role=administrator`
And I run `wp user generate --count=10`
And I run `wp database reset --author=testadmin7`
And I run `wp database reset --author=testadmin7 --yes`
And I run `wp user list --format=count`
Then STDOUT should be:
"""
Expand All @@ -59,7 +59,7 @@ Feature: Test reset behaviour

When I run `wp user create testadmin8 testadmin8@gmail.com --role=administrator`
And I run `wp term generate category --count=10`
And I run `wp database reset --author=testadmin8`
And I run `wp database reset --author=testadmin8 --yes`
And I run `wp term list category --format=count`
Then STDOUT should be:
"""
Expand All @@ -70,7 +70,7 @@ Feature: Test reset behaviour
And save STDOUT as {SAMPLE_POST_ID}
And I run `wp comment generate --post_id={SAMPLE_POST_ID}`
And I run `wp user create testadmin9 testadmin9@gmail.com --role=administrator`
And I run `wp database reset --author=testadmin9`
And I run `wp database reset --author=testadmin9 --yes`
And I run `wp comment list --format=count`
Then STDOUT should be:
"""
Expand All @@ -80,7 +80,7 @@ Feature: Test reset behaviour
When I run `wp user create testadmin10 testadmin10@gmail.com --role=administrator`
And I run `wp option get siteurl`
And save STDOUT as {SITE_URL}
And I run `wp database reset --author=testadmin10`
And I run `wp database reset --author=testadmin10 --yes`
And I run `wp option get siteurl`
Then STDOUT should be:
"""
Expand All @@ -92,7 +92,7 @@ Feature: Test reset behaviour

When I run `wp user create testadmin_bp testadmin_bp@gmail.com --role=administrator`
And I run `wp option set blog_public 0`
And I run `wp database reset --author=testadmin_bp`
And I run `wp database reset --author=testadmin_bp --yes`
And I run `wp option get blog_public`
Then STDOUT should be:
"""
Expand All @@ -105,7 +105,7 @@ Feature: Test reset behaviour
When I run `wp user create testadmin_home testadmin_home@gmail.com --role=administrator`
And I run `wp option set home https://example-home.test`
And I run `wp option set siteurl https://example-site.test`
And I run `wp database reset --author=testadmin_home`
And I run `wp database reset --author=testadmin_home --yes`
And I run `wp option get home`
Then STDOUT should be:
"""
Expand All @@ -124,7 +124,7 @@ Feature: Test reset behaviour
When I run `wp db query "CREATE TABLE wp_custom_test_reset (id INT PRIMARY KEY)"`
And I run `wp db query "CREATE TABLE custom_noprefix_reset (id INT PRIMARY KEY)"`
And I run `wp user create testadmin_ct testadmin_ct@gmail.com --role=administrator`
And I run `wp database reset --author=testadmin_ct`
And I run `wp database reset --author=testadmin_ct --yes`
And I run `wp db query "SHOW TABLES LIKE 'wp_custom_test_reset'" --skip-column-names`
Then STDOUT should not contain:
"""
Expand All @@ -140,9 +140,9 @@ Feature: Test reset behaviour
Given a WP install

When I run `wp user create adminA adminA@gmail.com --role=administrator`
And I run `wp database reset --author=adminA`
And I run `wp database reset --author=adminA --yes`
And I run `wp user create adminB adminB@gmail.com --role=administrator`
And I run `wp database reset --author=adminB`
And I run `wp database reset --author=adminB --yes`
And I try `wp user get adminA --field=login`
Then STDERR should contain:
"""
Expand All @@ -156,7 +156,7 @@ Feature: Test reset behaviour
When I run `wp user create testadmin_meta testadmin_meta@gmail.com --role=administrator`
And I run `wp eval 'update_user_meta( get_user_by( "login", "testadmin_meta" )->ID, "default_password_nag", true );'`
And I run `wp db query "UPDATE wp_users SET user_activation_key='testkey123' WHERE user_login='testadmin_meta'"`
And I run `wp database reset --author=testadmin_meta`
And I run `wp database reset --author=testadmin_meta --yes`
And I run `wp db query "SELECT user_activation_key FROM wp_users WHERE user_login='testadmin_meta'" --skip-column-names`
Then STDOUT should not contain:
"""
Expand Down
7 changes: 6 additions & 1 deletion src/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class DatabaseCommand extends WP_CLI_Command {
*
* --author=<username>
* : Administrator user you want to keep after reset.
*
* [--yes]
* : Answer yes to the confirmation message.
*
* ## EXAMPLES
*
* # Reset database and keep `admin` user.
* $ wp database reset --author=admin
* $ wp database reset --author=admin --yes
*
* @since 1.0.0
*
Expand Down Expand Up @@ -61,6 +64,8 @@ public function reset( $args, $assoc_args ) {
WP_CLI::error( 'User is not administrator.' );
}

WP_CLI::confirm( 'Are you sure you want to reset the database?', $assoc_args );

$this->reset_callback( $author_obj );
}

Expand Down
Loading