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
51 changes: 51 additions & 0 deletions features/runcommand.feature
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,54 @@ Feature: Run a WP-CLI command
"""
The used path is: /bad/path/
"""
Scenario: Check that required files are used from command arguments and ENV VAR
Given a WP installation
And a custom-cmd.php file:
"""
<?php
class Custom_Command extends WP_CLI_Command {
/**
* Custom command to test passing command_args via runcommand options
*
* @when after_wp_load
*/
public function echo_test( $args ) {
echo "test" . PHP_EOL;
}
}
WP_CLI::add_command( 'custom-command', 'Custom_Command' );
"""
And a env.php file:
"""
<?php
echo 'ENVIRONMENT REQUIRE' . PHP_EOL;
"""
And a env-2.php file:
"""
<?php
echo 'ENVIRONMENT REQUIRE 2' . PHP_EOL;
"""
When I run `WP_CLI_REQUIRE=env.php wp eval 'return null;' --skip-wordpress`
Then STDOUT should be:
"""
ENVIRONMENT REQUIRE
"""
When I run `WP_CLI_REQUIRE=env.php wp --require=custom-cmd.php custom-command echo_test`
Then STDOUT should be:
"""
ENVIRONMENT REQUIRE
test
"""
When I run `WP_CLI_REQUIRE='env.php,env-2.php' wp --require=custom-cmd.php custom-command echo_test`
Then STDOUT should be:
"""
ENVIRONMENT REQUIRE
ENVIRONMENT REQUIRE 2
test
"""
11 changes: 11 additions & 0 deletions php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public function __construct( $path ) {

$this->config[ $key ] = $details['default'];
}

$env_files = getenv( 'WP_CLI_REQUIRE' )
? array_filter( array_map( 'trim', explode( ',', getenv( 'WP_CLI_REQUIRE' ) ) ) )
: [];

if ( ! empty( $env_files ) ) {
if ( ! isset( $this->config['require'] ) ) {
$this->config['require'] = [];
}
$this->config['require'] = array_unique( array_merge( $env_files, $this->config['require'] ) );
}
}

/**
Expand Down