Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions features/shell.feature
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,49 @@ Feature: WordPress REPL
Error: The 'shutdown' hook has not fired yet
"""
And the return code should be 1

Scenario: Quiet mode suppresses return value output
Given a WP install
And a session file:
"""
$a = "hello";
"""

When I run `wp shell --basic --quiet < session`
Then STDOUT should be empty

Scenario: Quiet mode still shows echo output
Given a WP install
And a session file:
"""
echo "test output";
"""

When I run `wp shell --basic --quiet < session`
Then STDOUT should contain:
"""
test output
"""

Scenario: Quiet mode with expression
Given a WP install
And a session file:
"""
get_bloginfo('name');
"""

When I run `wp shell --basic --quiet < session`
Then STDOUT should be empty

Scenario: Normal mode shows return value
Given a WP install
And a session file:
"""
$a = "hello";
"""

When I run `wp shell --basic < session`
Then STDOUT should contain:
"""
string(5) "hello"
"""
8 changes: 7 additions & 1 deletion src/Shell_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class Shell_Command extends WP_CLI_Command {
*
* # Start a shell, ensuring the 'init' hook has already fired.
* $ wp shell --hook=init
*
* # Start a shell in quiet mode, suppressing return value output.
* $ wp shell --quiet
* wp> $a = "hello";
* wp>
*/
public function __invoke( $_, $assoc_args ) {
$hook = Utils\get_flag_value( $assoc_args, 'hook', '' );
Expand Down Expand Up @@ -71,6 +76,7 @@ public function __invoke( $_, $assoc_args ) {
*/
private function start_shell( $assoc_args ) {
$class = WP_CLI\Shell\REPL::class;
$quiet = (bool) WP_CLI::get_config( 'quiet' );

$implementations = array(
\Psy\Shell::class,
Expand Down Expand Up @@ -98,7 +104,7 @@ private function start_shell( $assoc_args ) {
/**
* @var class-string<WP_CLI\Shell\REPL> $class
*/
$repl = new $class( 'wp> ' );
$repl = new $class( 'wp> ', $quiet );
$repl->start();
}
Comment on lines +107 to 109
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --quiet flag is only compatible with the built-in WP_CLI\Shell\REPL implementation. When PsySH or Boris are used (which happens by default unless --basic is specified), the quiet flag will be ignored or cause errors. Boris\Boris constructor does not accept a second parameter, so passing $quiet on line 107 will cause a runtime error if Boris is available. PsySH also doesn't use the quiet flag. Consider either: (1) only passing $quiet when $class is WP_CLI\Shell\REPL::class, (2) implementing quiet mode support for other REPL implementations, or (3) documenting this limitation.

Copilot uses AI. Check for mistakes.
}
Expand Down
11 changes: 8 additions & 3 deletions src/WP_CLI/Shell/REPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class REPL {

private $history_file;

public function __construct( $prompt ) {
private $quiet;

public function __construct( $prompt, $quiet = false ) {
$this->prompt = $prompt;
$this->quiet = $quiet;

$this->set_history_file();
}
Expand Down Expand Up @@ -49,8 +52,10 @@ public function start() {
if ( 0 < strlen( $out ) ) {
echo rtrim( $out, "\n" ) . "\n";
}
echo '=> ';
var_dump( $evl );
if ( ! $this->quiet ) {
echo '=> ';
var_dump( $evl );
}
fwrite( STDOUT, (string) ob_get_clean() );
}
}
Expand Down