}
/**
- * Splits a list of arguments into positional and associative.
+ * Splits a list of arguments into positional, associative and config.
*
* @param string
* @return array
}
}
- return array( $regular_args, $assoc_args );
+ $runtime_config = array();
+
+ foreach ( $this->spec as $key => $details ) {
+ if ( true === $details['runtime'] ) {
+ self::handle_boolean_param( $assoc_args, $runtime_config, $key );
+ } elseif ( false !== $details['runtime'] ) {
+ if ( isset( $assoc_args[ $key ] ) ) {
+ $runtime_config[ $key ] = $assoc_args[ $key ];
+ unset( $assoc_args[ $key ] );
+ }
+ }
+ }
+
+ return array( $regular_args, $assoc_args, $runtime_config );
+ }
+
+ private static function handle_boolean_param( &$assoc_args, &$config, $param ) {
+ $subkeys = array(
+ "$param" => true,
+ "no-$param" => false
+ );
+
+ foreach ( $subkeys as $key => $value ) {
+ if ( isset( $assoc_args[ $key ] ) ) {
+ $config[ $param ] = $value;
+ }
+
+ unset( $assoc_args[ $key ] );
+ }
}
/**
return $sanitized_config;
}
-
- /**
- * Extract values from an associative array, according to the spec.
- */
- function split_special( &$assoc_args, &$config ) {
- foreach ( $this->spec as $key => $details ) {
- if ( true === $details['runtime'] ) {
- self::handle_boolean_param( $assoc_args, $config, $key );
- } elseif ( false !== $details['runtime'] ) {
- if ( isset( $assoc_args[ $key ] ) ) {
- $config[ $key ] = $assoc_args[ $key ];
- unset( $assoc_args[ $key ] );
- }
- }
- }
- }
-
- private static function handle_boolean_param( &$assoc_args, &$config, $param ) {
- $subkeys = array(
- "$param" => true,
- "no-$param" => false
- );
-
- foreach ( $subkeys as $key => $value ) {
- if ( isset( $assoc_args[ $key ] ) ) {
- $config[ $param ] = $value;
- }
-
- unset( $assoc_args[ $key ] );
- }
- }
}
return $this->$key;
}
- private static function get_config_path( &$assoc_args ) {
- if ( isset( $assoc_args['config'] ) && file_exists( $assoc_args['config'] ) ) {
- $path = $assoc_args['config'];
- unset( $assoc_args['config'] );
- return $path;
+ private static function get_config_path( $runtime_config ) {
+ if ( isset( $runtime_config['config'] ) && file_exists( $runtime_config['config'] ) ) {
+ return $runtime_config['config'];
}
$config_files = array(
'wp-cli.local.yml',
'wp-cli.yml'
);
- // Stop looking upward when we find we have emerged from a subdirectory install into a parent install
- $stop_check = function ( $dir ) {
+
+ // Stop looking upward when we find we have emerged from a subdirectory
+ // install into a parent install
+ $path = Utils\find_file_upward( $config_files, getcwd(), function ( $dir ) {
static $wp_load_count = 0;
$wp_load_path = $dir . DIRECTORY_SEPARATOR . 'wp-load.php';
if ( file_exists( $wp_load_path ) ) {
$wp_load_count += 1;
}
return $wp_load_count > 1;
- };
- $path = Utils\find_file_upward( $config_files, getcwd(), $stop_check );
+ } );
+
if ( $path ) {
return $path;
}
}
// Transparently convert old syntaxes
- private static function back_compat_conversions( $r ) {
- list( $args, $assoc_args ) = $r;
-
+ private static function back_compat_conversions( $args, $assoc_args ) {
// foo --help -> help foo
if ( isset( $assoc_args['help'] ) ) {
array_unshift( $args, 'help' );
}
public function before_wp_load() {
+ list( $args, $assoc_args, $runtime_config ) = \WP_CLI::$configurator->parse_args(
+ array_slice( $GLOBALS['argv'], 1 ) );
+
list( $this->arguments, $this->assoc_args ) = self::back_compat_conversions(
- \WP_CLI::$configurator->parse_args( array_slice( $GLOBALS['argv'], 1 ) ) );
+ $args, $assoc_args );
- $this->config_path = self::get_config_path( $this->assoc_args );
+ $this->config_path = self::get_config_path( $runtime_config );
- $this->config = \WP_CLI::$configurator->load_config( $this->config_path );
+ $local_config = \WP_CLI::$configurator->load_config( $this->config_path );
- \WP_CLI::$configurator->split_special( $this->assoc_args, $this->config );
+ $this->config = array_merge( $local_config, $runtime_config );
if ( !isset( $this->config['path'] ) ) {
$this->config['path'] = dirname( Utils\find_file_upward( 'wp-load.php' ) );