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
20 changes: 20 additions & 0 deletions features/core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ Feature: Manage WordPress installation
http://localhost:8001
"""

Scenario: Install WordPress by prompting for the admin email and password
Given an empty directory
And WP files
And wp-config.php
And a database
And a session file:
"""
wpcli
admin@example.com
"""

When I run `wp core install --url=localhost:8001 --title=Test --admin_user=wpcli --prompt=admin_email,admin_password < session`
Then STDOUT should not be empty

When I run `wp eval 'echo home_url();'`
Then STDOUT should be:
"""
http://localhost:8001
"""

Scenario: Install WordPress with an https scheme
Given an empty directory
And WP files
Expand Down
16 changes: 16 additions & 0 deletions php/WP_CLI/Dispatcher/Subcommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,27 @@ private function prompt_args( $args, $assoc_args ) {

$spec = array_values( $spec );

$prompt_args = WP_CLI::get_config( 'prompt' );
if ( true !== $prompt_args ) {
$prompt_args = explode( ',', $prompt_args );
}

// 'positional' arguments are positional (aka zero-indexed)
// so $args needs to be reset before prompting for new arguments
$args = array();
foreach( $spec as $key => $spec_arg ) {

// When prompting for specific arguments (e.g. --prompt=user_pass),
// ignore all arguments that don't match
if ( is_array( $prompt_args ) ) {
if ( 'assoc' !== $spec_arg['type'] ) {
continue;
}
if ( ! in_array( $spec_arg['name'], $prompt_args, true ) ) {
continue;
}
}

$current_prompt = ( $key + 1 ) . '/' . count( $spec ) . ' ';
$default = ( $spec_arg['optional'] ) ? '' : false;

Expand Down
8 changes: 8 additions & 0 deletions php/commands/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ private static function get_initial_locale() {
* $ define( 'WP_DEBUG_LOG', true );
* $ PHP
* Success: Generated 'wp-config.php' file.
*
* # Avoid disclosing password to bash history by reading from password.txt
* $ wp core config --dbname=testing --dbuser=wp --prompt=dbpass < password.txt
* Success: Generated 'wp-config.php' file.
*/
public function config( $_, $assoc_args ) {
global $wp_version;
Expand Down Expand Up @@ -469,8 +473,12 @@ public function is_installed( $_, $assoc_args ) {
*
* ## EXAMPLES
*
* # Install WordPress in 5 seconds
* $ wp core install --url=example.com --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@example.com
* Success: WordPress installed successfully.
*
* # Install WordPress without disclosing admin_password to bash history
* $ wp core install --url=example.com --title=Example --admin_user=supervisor --admin_email=info@example.com --prompt=admin_password < admin_password.txt
*/
public function install( $args, $assoc_args ) {
if ( $this->_install( $assoc_args ) ) {
Expand Down
4 changes: 2 additions & 2 deletions php/config-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
),

'prompt' => array(
'runtime' => '',
'runtime' => '[=<assoc>]',
'file' => false,
'default' => false,
'desc' => 'Prompt the user to enter values for all command arguments.',
'desc' => 'Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values.',
),

'quiet' => array(
Expand Down