Skip to content

Commit 58d4632

Browse files
Copilotswissspidy
andcommitted
Simplify script path detection and use runner config for preserved args
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 297d895 commit 58d4632

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

src/Shell_Command.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,10 @@ private function restart_process( $assoc_args ) {
145145

146146
// Get the WP-CLI script path
147147
$wp_cli_script = null;
148-
foreach ( array( 'argv', '_SERVER' ) as $source ) {
149-
if ( 'argv' === $source && is_array( $GLOBALS['argv'] ) && isset( $GLOBALS['argv'][0] ) ) {
150-
$wp_cli_script = $GLOBALS['argv'][0];
151-
break;
152-
} elseif ( '_SERVER' === $source && is_array( $_SERVER['argv'] ) && isset( $_SERVER['argv'][0] ) ) {
153-
$wp_cli_script = $_SERVER['argv'][0];
154-
break;
155-
}
148+
if ( isset( $GLOBALS['argv'][0] ) ) {
149+
$wp_cli_script = $GLOBALS['argv'][0];
150+
} elseif ( isset( $_SERVER['argv'][0] ) ) {
151+
$wp_cli_script = $_SERVER['argv'][0];
156152
}
157153

158154
if ( ! $wp_cli_script ) {
@@ -172,13 +168,16 @@ private function restart_process( $assoc_args ) {
172168
$args[] = '--watch=' . $watch_path;
173169
}
174170

175-
// Add the path argument if present in $_SERVER
176-
if ( isset( $_SERVER['argv'] ) && is_array( $_SERVER['argv'] ) ) {
177-
foreach ( $_SERVER['argv'] as $arg ) {
178-
if ( is_string( $arg ) && '--path=' === substr( $arg, 0, 7 ) ) {
179-
$args[] = $arg;
180-
}
181-
}
171+
// Add global config values to preserve the environment after restart
172+
$config = WP_CLI::get_runner()->config;
173+
if ( isset( $config['path'] ) ) {
174+
$args[] = '--path=' . $config['path'];
175+
}
176+
if ( isset( $config['user'] ) ) {
177+
$args[] = '--user=' . $config['user'];
178+
}
179+
if ( isset( $config['url'] ) ) {
180+
$args[] = '--url=' . $config['url'];
182181
}
183182

184183
WP_CLI::log( 'Restarting shell in new process...' );

0 commit comments

Comments
 (0)