php/WP_CLI/Runner.php
private function generate_ssh_command( $bits, $wp_command ) {
		$escaped_command = '';

		// Set default values.
		foreach ( array( 'scheme', 'user', 'host', 'port', 'path' ) as $bit ) {
			if ( ! isset( $bits[ $bit ] ) ) {
				$bits[ $bit ] = null;
			}

			WP_CLI::debug( 'SSH ' . $bit . ': ' . $bits[ $bit ], 'bootstrap' );
		}

		$is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT );

		if ( 'docker' === $bits['scheme'] ) {
			$command = 'docker exec %s%s%s sh -c %s';

			$escaped_command = sprintf(
				$command,
				$bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '',
				$is_tty ? '-t ' : '',
				escapeshellarg( $bits['host'] ),
				escapeshellarg( $wp_command )
			);
		}

		if ( 'docker-compose' === $bits['scheme'] ) {
			$command = 'docker-compose exec %s%s%s sh -c %s';

			$escaped_command = sprintf(
				$command,
				$bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '',
				$is_tty ? '' : '-T ',
				escapeshellarg( $bits['host'] ),
				escapeshellarg( $wp_command )
			);
		}

		// Vagrant ssh-config.
		if ( 'vagrant' === $bits['scheme'] ) {
			$command = 'vagrant ssh -c %s %s';

			$escaped_command = sprintf(
				$command,
				escapeshellarg( $wp_command ),
				escapeshellarg( $bits['host'] )
			);
		}

		// Default scheme is SSH.
		if ( 'ssh' === $bits['scheme'] || null === $bits['scheme'] ) {
			$command = 'ssh -q %s%s %s %s';

			if ( $bits['user'] ) {
				$bits['host'] = $bits['user'] . '@' . $bits['host'];
			}

			$escaped_command = sprintf(
				$command,
				$bits['port'] ? '-p ' . (int) $bits['port'] . ' ' : '',
				escapeshellarg( $bits['host'] ),
				$is_tty ? '-t' : '-T',
				escapeshellarg( $wp_command )
			);
		}

		WP_CLI::debug( 'Running SSH command: ' . $escaped_command, 'bootstrap' );

		return $escaped_command;
	}
private function generate_ssh_command( $bits, $wp_command ) {
		$escaped_command = '';

		// Set default values.
		foreach ( array( 'scheme', 'user', 'host', 'port', 'path' ) as $bit ) {
			if ( ! isset( $bits[ $bit ] ) ) {
				$bits[ $bit ] = null;
			}

			WP_CLI::debug( 'SSH ' . $bit . ': ' . $bits[ $bit ], 'bootstrap' );
		}

		$is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT );

		if ( 'docker' === $bits['scheme'] ) {
			$command = 'docker exec %s%s%s sh -c %s';

			$escaped_command = sprintf(
				$command,
				$bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '',
				$is_tty ? '-t ' : '',
				escapeshellarg( $bits['host'] ),
				escapeshellarg( $wp_command )
			);
		}

		if ( 'docker-compose' === $bits['scheme'] ) {
			$command = 'docker-compose exec %s%s%s sh -c %s';

			$escaped_command = sprintf(
				$command,
				$bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '',
				$is_tty ? '' : '-T ',
				escapeshellarg( $bits['host'] ),
				escapeshellarg( $wp_command )
			);
		}

		// Vagrant ssh-config.
		if ( 'vagrant' === $bits['scheme'] ) {
			$command = 'vagrant ssh -c %s %s';

			$escaped_command = sprintf(
				$command,
				escapeshellarg( $wp_command ),
				escapeshellarg( $bits['host'] )
			);
		}

		// Default scheme is SSH.
		if ( 'ssh' === $bits['scheme'] || null === $bits['scheme'] ) {
			$command = 'ssh -q %s%s %s %s';

			if ( $bits['user'] ) {
				$bits['host'] = $bits['user'] . '@' . $bits['host'];
			}

			$escaped_command = sprintf(
				$command,
				$bits['port'] ? '-p ' . (int) $bits['port'] . ' ' : '',
				escapeshellarg( $bits['host'] ),
				$is_tty ? '-t' : '-T',
				escapeshellarg( $wp_command )
			);
		}

		WP_CLI::debug( 'Running SSH command: ' . $escaped_command, 'bootstrap' );

		return $escaped_command;
	}
private function generate_ssh_command ( $ bits , $ wp_command ) { $ escaped_command = '' ; // Set default values. foreach ( array ( 'scheme' , 'user' , 'host' , 'port' , 'path' ) as $ bit ) { if ( ! isset ( $ bits [ $ bit ] ) ) { $ bits [ $ bit ] = null ; } WP_CLI :: debug ( 'SSH ' . $ bit . ': ' . $ bits [ $ bit ] , 'bootstrap' ) ; } $ is_tty = function_exists ( 'posix_isatty' ) && posix_isatty ( STDOUT ) ; if ( 'docker' === $ bits [ 'scheme' ] ) { $ command = 'docker exec %s%s%s sh -c %s' ; $ escaped_command = sprintf ( $ command , $ bits [ 'user' ] ? '--user ' . escapeshellarg ( $ bits [ 'user' ] ) . ' ' : '' , $ is_tty ? '-t ' : '' , escapeshellarg ( $ bits [ 'host' ] ) , escapeshellarg ( $ wp_command ) ) ; } if ( 'docker-compose' === $ bits [ 'scheme' ] ) { $ command = 'docker-compose exec %s%s%s sh -c %s' ; $ escaped_command = sprintf ( $ command , $ bits [ 'user' ] ? '--user ' . escapeshellarg ( $ bits [ 'user' ] ) . ' ' : '' , $ is_tty ? '' : '-T ' , escapeshellarg ( $ bits [ 'host' ] ) , escapeshellarg ( $ wp_command ) ) ; } // Vagrant ssh-config. if ( 'vagrant' === $ bits [ 'scheme' ] ) { $ command = 'vagrant ssh -c %s %s' ; $ escaped_command = sprintf ( $ command , escapeshellarg ( $ wp_command ) , escapeshellarg ( $ bits [ 'host' ] ) ) ; } // Default scheme is SSH. if ( 'ssh' === $ bits [ 'scheme' ] || null === $ bits [ 'scheme' ] ) { $ command = 'ssh -q %s%s %s %s' ; if ( $ bits [ 'user' ] ) { $ bits [ 'host' ] = $ bits [ 'user' ] . '@' . $ bits [ 'host' ] ; } $ escaped_command = sprintf ( $ command , $ bits [ 'port' ] ? '-p ' . ( int ) $ bits [ 'port' ] . ' ' : '' , escapeshellarg ( $ bits [ 'host' ] ) , $ is_tty ? '-t' : '-T' , escapeshellarg ( $ wp_command ) ) ; } WP_CLI :: debug ( 'Running SSH command: ' . $ escaped_command , 'bootstrap' ) ; return $ escaped_command ; }
Generate a shell command from the parsed connection string.

@param array  $bits       Parsed connection string.
@param string $wp_command WP-CLI command to run.
@return string
Generate a shell command from the parsed connection string .