Skip to content

Commit b26a757

Browse files
Copilotswissspidy
andauthored
Allow wp config create to defer DB_NAME/DB_USER initialization via --skip-check (#223)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 8d042e2 commit b26a757

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

features/config-create.feature

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,48 @@ Feature: Create a wp-config file
163163
Error: Database connection error
164164
"""
165165
166+
Scenario: Missing --dbname with --skip-check
167+
Given an empty directory
168+
And WP files
169+
170+
When I run `wp config create --skip-check --dbuser=someuser`
171+
Then the wp-config.php file should contain:
172+
"""
173+
define( 'DB_NAME', '' );
174+
"""
175+
And the wp-config.php file should contain:
176+
"""
177+
define( 'DB_USER', 'someuser' );
178+
"""
179+
180+
Scenario: Missing --dbuser with --skip-check
181+
Given an empty directory
182+
And WP files
183+
184+
When I run `wp config create --skip-check --dbname=somedb`
185+
Then the wp-config.php file should contain:
186+
"""
187+
define( 'DB_NAME', 'somedb' );
188+
"""
189+
And the wp-config.php file should contain:
190+
"""
191+
define( 'DB_USER', '' );
192+
"""
193+
166194
@require-mysql
167-
Scenario: Missing --dbname or --dbuser without SQLite integration
195+
Scenario: Missing --dbname or --dbuser without --skip-check
168196
Given an empty directory
169197
And WP files
170198
171-
When I try `wp config create --skip-check --dbuser=someuser`
199+
When I try `wp config create --dbuser=someuser`
172200
Then the return code should be 1
173201
And STDERR should contain:
174202
"""
175203
Error: Parameter errors:
176204
missing --dbname parameter (Set the database name.)
177205
"""
178206
179-
When I try `wp config create --skip-check --dbname=somedb`
207+
When I try `wp config create --dbname=somedb`
180208
Then the return code should be 1
181209
And STDERR should contain:
182210
"""

src/Config_Command.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ private static function get_initial_locale() {
121121
* ## OPTIONS
122122
*
123123
* [--dbname=<dbname>]
124-
* : Set the database name. Required unless the SQLite integration drop-in is detected.
124+
* : Set the database name. Required unless `--skip-check` is used or the SQLite integration drop-in is detected.
125125
*
126126
* [--dbuser=<dbuser>]
127-
* : Set the database user. Required unless the SQLite integration drop-in is detected.
127+
* : Set the database user. Required unless `--skip-check` is used or the SQLite integration drop-in is detected.
128128
*
129129
* [--dbpass=<dbpass>]
130130
* : Set the database user password.
@@ -209,6 +209,8 @@ public function create( $_, $assoc_args ) {
209209
}
210210

211211
$defaults = [
212+
'dbname' => '',
213+
'dbuser' => '',
212214
'dbhost' => 'localhost',
213215
'dbpass' => '',
214216
'dbprefix' => 'wp_',
@@ -222,7 +224,7 @@ public function create( $_, $assoc_args ) {
222224

223225
$is_sqlite = self::is_sqlite_integration_active();
224226

225-
if ( ! $is_sqlite ) {
227+
if ( ! $is_sqlite && ! Utils\get_flag_value( $assoc_args, 'skip-check' ) ) {
226228
$errors = [];
227229
if ( empty( $assoc_args['dbname'] ) ) {
228230
$errors[] = 'missing --dbname parameter (Set the database name.)';

0 commit comments

Comments
 (0)