WP_CLI

Completions::get_command()privateWP-CLI 1.0

Get the specific WP-CLI command that is being referenced.

Метод класса: Completions{}

Хуков нет.

Возвращает

Массив|Разное. Array with command and arguments, or error result if command detection failed.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_command( $words );
$words(массив) (обязательный)
Individual input line words.

Код Completions::get_command() WP-CLI 2.8.0-alpha

private function get_command( $words ) {
	$positional_args = [];
	$assoc_args      = [];

	foreach ( $words as $arg ) {
		if ( preg_match( '|^--([^=]+)=?|', $arg, $matches ) ) {
			$assoc_args[ $matches[1] ] = true;
		} else {
			$positional_args[] = $arg;
		}
	}

	$r = WP_CLI::get_runner()->find_command_to_run( $positional_args );
	if ( ! is_array( $r ) && array_pop( $positional_args ) === $this->cur_word ) {
		$r = WP_CLI::get_runner()->find_command_to_run( $positional_args );
	}

	if ( ! is_array( $r ) ) {
		return $r;
	}

	list( $command, $args ) = $r;

	return [ $command, $args, $assoc_args ];
}