Skip to content

Commit d639d99

Browse files
committed
Add docker compose v2 command support in ssh command generation
1 parent 9239cff commit d639d99

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

php/WP_CLI/Runner.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ private function generate_ssh_command( $bits, $wp_command ) {
564564
WP_CLI::debug( 'SSH ' . $bit . ': ' . $bits[ $bit ], 'bootstrap' );
565565
}
566566

567-
$is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT );
567+
$is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT );
568+
$docker_compose_cmd = ! empty( Process::create( Utils\esc_cmd( 'docker compose %s', 'version' ) )->run()->stdout )
569+
? 'docker compose'
570+
: 'docker-compose';
568571

569572
if ( 'docker' === $bits['scheme'] ) {
570573
$command = 'docker exec %s%s%s sh -c %s';
@@ -579,10 +582,11 @@ private function generate_ssh_command( $bits, $wp_command ) {
579582
}
580583

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

584587
$escaped_command = sprintf(
585588
$command,
589+
$docker_compose_cmd,
586590
$bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '',
587591
$is_tty ? '' : '-T ',
588592
escapeshellarg( $bits['host'] ),
@@ -591,10 +595,11 @@ private function generate_ssh_command( $bits, $wp_command ) {
591595
}
592596

593597
if ( 'docker-compose-run' === $bits['scheme'] ) {
594-
$command = 'docker-compose run %s%s%s %s';
598+
$command = '%s run %s%s%s %s';
595599

596600
$escaped_command = sprintf(
597601
$command,
602+
$docker_compose_cmd,
598603
$bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '',
599604
$is_tty ? '' : '-T ',
600605
escapeshellarg( $bits['host'] ),

0 commit comments

Comments
 (0)