php/WP_CLI/Runner.php
public function find_command_to_run( $args ) {
		$command = \WP_CLI::get_root_command();

		WP_CLI::do_hook( 'find_command_to_run_pre' );

		$cmd_path = array();

		while ( ! empty( $args ) && $command->can_have_subcommands() ) {
			$cmd_path[] = $args[0];
			$full_name  = implode( ' ', $cmd_path );

			$subcommand = $command->find_subcommand( $args );

			if ( ! $subcommand ) {
				if ( count( $cmd_path ) > 1 ) {
					$child       = array_pop( $cmd_path );
					$parent_name = implode( ' ', $cmd_path );
					$suggestion  = $this->get_subcommand_suggestion( $child, $command );
					return sprintf(
						"'%s' is not a registered subcommand of '%s'. See 'wp help %s' for available subcommands.%s",
						$child,
						$parent_name,
						$parent_name,
						! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
					);
				}

				$suggestion = $this->get_subcommand_suggestion( $full_name, $command );

				return sprintf(
					"'%s' is not a registered wp command. See 'wp help' for available commands.%s",
					$full_name,
					! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
				);
			}

			if ( $this->is_command_disabled( $subcommand ) ) {
				return sprintf(
					"The '%s' command has been disabled from the config file.",
					$full_name
				);
			}

			$command = $subcommand;
		}

		return array( $command, $args, $cmd_path );
	}
public function find_command_to_run( $args ) {
		$command = \WP_CLI::get_root_command();

		WP_CLI::do_hook( 'find_command_to_run_pre' );

		$cmd_path = array();

		while ( ! empty( $args ) && $command->can_have_subcommands() ) {
			$cmd_path[] = $args[0];
			$full_name  = implode( ' ', $cmd_path );

			$subcommand = $command->find_subcommand( $args );

			if ( ! $subcommand ) {
				if ( count( $cmd_path ) > 1 ) {
					$child       = array_pop( $cmd_path );
					$parent_name = implode( ' ', $cmd_path );
					$suggestion  = $this->get_subcommand_suggestion( $child, $command );
					return sprintf(
						"'%s' is not a registered subcommand of '%s'. See 'wp help %s' for available subcommands.%s",
						$child,
						$parent_name,
						$parent_name,
						! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
					);
				}

				$suggestion = $this->get_subcommand_suggestion( $full_name, $command );

				return sprintf(
					"'%s' is not a registered wp command. See 'wp help' for available commands.%s",
					$full_name,
					! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
				);
			}

			if ( $this->is_command_disabled( $subcommand ) ) {
				return sprintf(
					"The '%s' command has been disabled from the config file.",
					$full_name
				);
			}

			$command = $subcommand;
		}

		return array( $command, $args, $cmd_path );
	}
public function find_command_to_run ( $ args ) { $ command = \ WP_CLI :: get_root_command ( ) ; WP_CLI :: do_hook ( 'find_command_to_run_pre' ) ; $ cmd_path = array ( ) ; while ( ! empty ( $ args ) && $ command -> can_have_subcommands ( ) ) { $ cmd_path [ ] = $ args [ 0 ] ; $ full_name = implode ( ' ' , $ cmd_path ) ; $ subcommand = $ command -> find_subcommand ( $ args ) ; if ( ! $ subcommand ) { if ( count ( $ cmd_path ) > 1 ) { $ child = array_pop ( $ cmd_path ) ; $ parent_name = implode ( ' ' , $ cmd_path ) ; $ suggestion = $ this -> get_subcommand_suggestion ( $ child , $ command ) ; return sprintf ( "'%s' is not a registered subcommand of '%s'. See 'wp help %s' for available subcommands.%s" , $ child , $ parent_name , $ parent_name , ! empty ( $ suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : '' ) ; } $ suggestion = $ this -> get_subcommand_suggestion ( $ full_name , $ command ) ; return sprintf ( "'%s' is not a registered wp command. See 'wp help' for available commands.%s" , $ full_name , ! empty ( $ suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : '' ) ; } if ( $ this -> is_command_disabled ( $ subcommand ) ) { return sprintf ( "The '%s' command has been disabled from the config file." , $ full_name ) ; } $ command = $ subcommand ; } return array ( $ command , $ args , $ cmd_path ) ; }
Given positional arguments, find the command to execute.

@param array $args
@return array|string Command, args, and path on success; error message on failure
Given positional arguments find the command to execute .