@@ -503,6 +503,9 @@ private function run_ssh_command( $connection_string ) {
503503
504504 $ pre_cmd = rtrim ( $ pre_cmd , '; ' ) . '; ' ;
505505 }
506+ if ( ! empty ( $ bits ['path ' ] ) ) {
507+ $ pre_cmd .= 'cd ' . escapeshellarg ( $ bits ['path ' ] ) . '; ' ;
508+ }
506509
507510 $ env_vars = '' ;
508511 if ( getenv ( 'WP_CLI_STRICT_ARGS_MODE ' ) ) {
@@ -572,67 +575,50 @@ private function generate_ssh_command( $bits, $wp_command ) {
572575 WP_CLI ::debug ( 'SSH ' . $ bit . ': ' . $ bits [ $ bit ], 'bootstrap ' );
573576 }
574577
575- /*
576- * posix_isatty(STDIN) is generally true unless something was passed on stdin
577- * If autodetection leads to false (fd on stdin), then `-i` is passed to `docker` cmd
578- * (unless WP_CLI_DOCKER_NO_INTERACTIVE is set)
579- */
580- $ is_stdout_tty = function_exists ( 'posix_isatty ' ) && posix_isatty ( STDOUT );
581- $ is_stdin_tty = function_exists ( 'posix_isatty ' ) ? posix_isatty ( STDIN ) : true ;
582-
578+ $ is_tty = function_exists ( 'posix_isatty ' ) && posix_isatty ( STDOUT );
583579 $ docker_compose_v2_version_cmd = Utils \esc_cmd ( Utils \force_env_on_nix_systems ( 'docker ' ) . ' compose %s ' , 'version ' );
584580 $ docker_compose_cmd = ! empty ( Process::create ( $ docker_compose_v2_version_cmd )->run ()->stdout )
585581 ? 'docker compose '
586582 : 'docker-compose ' ;
587583
588584 if ( 'docker ' === $ bits ['scheme ' ] ) {
589- $ command = 'docker exec %s%s%s%s%s sh -c %s ' ;
585+ $ command = 'docker exec %s%s%s sh -c %s ' ;
590586
591587 $ escaped_command = sprintf (
592588 $ command ,
593589 $ bits ['user ' ] ? '--user ' . escapeshellarg ( $ bits ['user ' ] ) . ' ' : '' ,
594- $ bits ['path ' ] ? '--workdir ' . escapeshellarg ( $ bits ['path ' ] ) . ' ' : '' ,
595- $ is_stdout_tty && ! getenv ( 'WP_CLI_DOCKER_NO_TTY ' ) ? '-t ' : '' ,
596- ! $ is_stdin_tty && ! getenv ( 'WP_CLI_DOCKER_NO_INTERACTIVE ' ) ? '-i ' : '' ,
590+ $ is_tty ? '-t ' : '' ,
597591 escapeshellarg ( $ bits ['host ' ] ),
598592 escapeshellarg ( $ wp_command )
599593 );
600594 }
601595
602596 if ( 'docker-compose ' === $ bits ['scheme ' ] ) {
603- $ command = '%s exec %s%s%s%s sh -c %s ' ;
597+ $ command = '%s exec %s%s%s sh -c %s ' ;
604598
605599 $ escaped_command = sprintf (
606600 $ command ,
607601 $ docker_compose_cmd ,
608602 $ bits ['user ' ] ? '--user ' . escapeshellarg ( $ bits ['user ' ] ) . ' ' : '' ,
609- $ bits ['path ' ] ? '--workdir ' . escapeshellarg ( $ bits ['path ' ] ) . ' ' : '' ,
610- $ is_stdout_tty || getenv ( 'WP_CLI_DOCKER_NO_TTY ' ) ? '' : '-T ' ,
603+ $ is_tty ? '' : '-T ' ,
611604 escapeshellarg ( $ bits ['host ' ] ),
612605 escapeshellarg ( $ wp_command )
613606 );
614607 }
615608
616609 if ( 'docker-compose-run ' === $ bits ['scheme ' ] ) {
617- $ command = '%s run %s%s%s%s%s %s ' ;
610+ $ command = '%s run %s%s%s %s ' ;
618611
619612 $ escaped_command = sprintf (
620613 $ command ,
621614 $ docker_compose_cmd ,
622615 $ bits ['user ' ] ? '--user ' . escapeshellarg ( $ bits ['user ' ] ) . ' ' : '' ,
623- $ bits ['path ' ] ? '--workdir ' . escapeshellarg ( $ bits ['path ' ] ) . ' ' : '' ,
624- $ is_stdout_tty || getenv ( 'WP_CLI_DOCKER_NO_TTY ' ) ? '' : '-T ' ,
625- ! $ is_stdin_tty && ! getenv ( 'WP_CLI_DOCKER_NO_INTERACTIVE ' ) ? '-i ' : '' ,
616+ $ is_tty ? '' : '-T ' ,
626617 escapeshellarg ( $ bits ['host ' ] ),
627618 $ wp_command
628619 );
629620 }
630621
631- // For "vagrant" & "ssh" schemes which don't provide a working-directory option, use `cd`
632- if ( $ bits ['path ' ] ) {
633- $ wp_command = 'cd ' . escapeshellarg ( $ bits ['path ' ] ) . '; ' . $ wp_command ;
634- }
635-
636622 // Vagrant ssh-config.
637623 if ( 'vagrant ' === $ bits ['scheme ' ] ) {
638624 $ cache = WP_CLI ::get_cache ();
@@ -689,7 +675,7 @@ private function generate_ssh_command( $bits, $wp_command ) {
689675 $ bits ['proxyjump ' ] ? sprintf ( '-J %s ' , escapeshellarg ( $ bits ['proxyjump ' ] ) ) : '' ,
690676 $ bits ['port ' ] ? sprintf ( '-p %d ' , (int ) $ bits ['port ' ] ) : '' ,
691677 $ bits ['key ' ] ? sprintf ( '-i %s ' , escapeshellarg ( $ bits ['key ' ] ) ) : '' ,
692- $ is_stdout_tty ? '-t ' : '-T ' ,
678+ $ is_tty ? '-t ' : '-T ' ,
693679 WP_CLI ::get_config ( 'debug ' ) ? '-vvv ' : '-q ' ,
694680 ];
695681
0 commit comments