From 7841d8f401736c9e209936af62d5a282e834f377 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 25 Feb 2025 17:32:21 +0100 Subject: [PATCH] Revert "docker scheme: working-directory and stdin passing" --- php/WP_CLI/Runner.php | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index be3380a480..4779768c96 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -503,6 +503,9 @@ private function run_ssh_command( $connection_string ) { $pre_cmd = rtrim( $pre_cmd, ';' ) . '; '; } + if ( ! empty( $bits['path'] ) ) { + $pre_cmd .= 'cd ' . escapeshellarg( $bits['path'] ) . '; '; + } $env_vars = ''; if ( getenv( 'WP_CLI_STRICT_ARGS_MODE' ) ) { @@ -572,67 +575,50 @@ private function generate_ssh_command( $bits, $wp_command ) { WP_CLI::debug( 'SSH ' . $bit . ': ' . $bits[ $bit ], 'bootstrap' ); } - /* - * posix_isatty(STDIN) is generally true unless something was passed on stdin - * If autodetection leads to false (fd on stdin), then `-i` is passed to `docker` cmd - * (unless WP_CLI_DOCKER_NO_INTERACTIVE is set) - */ - $is_stdout_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT ); - $is_stdin_tty = function_exists( 'posix_isatty' ) ? posix_isatty( STDIN ) : true; - + $is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT ); $docker_compose_v2_version_cmd = Utils\esc_cmd( Utils\force_env_on_nix_systems( 'docker' ) . ' compose %s', 'version' ); $docker_compose_cmd = ! empty( Process::create( $docker_compose_v2_version_cmd )->run()->stdout ) ? 'docker compose' : 'docker-compose'; if ( 'docker' === $bits['scheme'] ) { - $command = 'docker exec %s%s%s%s%s sh -c %s'; + $command = 'docker exec %s%s%s sh -c %s'; $escaped_command = sprintf( $command, $bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '', - $bits['path'] ? '--workdir ' . escapeshellarg( $bits['path'] ) . ' ' : '', - $is_stdout_tty && ! getenv( 'WP_CLI_DOCKER_NO_TTY' ) ? '-t ' : '', - ! $is_stdin_tty && ! getenv( 'WP_CLI_DOCKER_NO_INTERACTIVE' ) ? '-i ' : '', + $is_tty ? '-t ' : '', escapeshellarg( $bits['host'] ), escapeshellarg( $wp_command ) ); } if ( 'docker-compose' === $bits['scheme'] ) { - $command = '%s exec %s%s%s%s sh -c %s'; + $command = '%s exec %s%s%s sh -c %s'; $escaped_command = sprintf( $command, $docker_compose_cmd, $bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '', - $bits['path'] ? '--workdir ' . escapeshellarg( $bits['path'] ) . ' ' : '', - $is_stdout_tty || getenv( 'WP_CLI_DOCKER_NO_TTY' ) ? '' : '-T ', + $is_tty ? '' : '-T ', escapeshellarg( $bits['host'] ), escapeshellarg( $wp_command ) ); } if ( 'docker-compose-run' === $bits['scheme'] ) { - $command = '%s run %s%s%s%s%s %s'; + $command = '%s run %s%s%s %s'; $escaped_command = sprintf( $command, $docker_compose_cmd, $bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '', - $bits['path'] ? '--workdir ' . escapeshellarg( $bits['path'] ) . ' ' : '', - $is_stdout_tty || getenv( 'WP_CLI_DOCKER_NO_TTY' ) ? '' : '-T ', - ! $is_stdin_tty && ! getenv( 'WP_CLI_DOCKER_NO_INTERACTIVE' ) ? '-i ' : '', + $is_tty ? '' : '-T ', escapeshellarg( $bits['host'] ), $wp_command ); } - // For "vagrant" & "ssh" schemes which don't provide a working-directory option, use `cd` - if ( $bits['path'] ) { - $wp_command = 'cd ' . escapeshellarg( $bits['path'] ) . '; ' . $wp_command; - } - // Vagrant ssh-config. if ( 'vagrant' === $bits['scheme'] ) { $cache = WP_CLI::get_cache(); @@ -689,7 +675,7 @@ private function generate_ssh_command( $bits, $wp_command ) { $bits['proxyjump'] ? sprintf( '-J %s', escapeshellarg( $bits['proxyjump'] ) ) : '', $bits['port'] ? sprintf( '-p %d', (int) $bits['port'] ) : '', $bits['key'] ? sprintf( '-i %s', escapeshellarg( $bits['key'] ) ) : '', - $is_stdout_tty ? '-t' : '-T', + $is_tty ? '-t' : '-T', WP_CLI::get_config( 'debug' ) ? '-vvv' : '-q', ];