WP_CLI
Completions::get_command()
Get the specific WP-CLI command that is being referenced.
Method of the class: Completions{}
No Hooks.
Return
Array|Mixed
. Array with command and arguments, or error result if command detection failed.
Usage
// private - for code of main (parent) class only $result = $this->get_command( $words );
- $words(array) (required)
- Individual input line words.
Completions::get_command() Completions::get command code 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 ]; }