File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -220,3 +220,49 @@ Feature: WordPress REPL
220220 Error: The 'shutdown' hook has not fired yet
221221 """
222222 And the return code should be 1
223+
224+ Scenario: Quiet mode suppresses return value output
225+ Given a WP install
226+ And a session file:
227+ """
228+ $a = "hello" ;
229+ """
230+
231+ When I run `wp shell --basic --quiet < session`
232+ Then STDOUT should be empty
233+
234+ Scenario: Quiet mode still shows echo output
235+ Given a WP install
236+ And a session file:
237+ """
238+ echo "test output" ;
239+ """
240+
241+ When I run `wp shell --basic --quiet < session`
242+ Then STDOUT should contain:
243+ """
244+ test output
245+ """
246+
247+ Scenario: Quiet mode with expression
248+ Given a WP install
249+ And a session file:
250+ """
251+ get_bloginfo('name' );
252+ """
253+
254+ When I run `wp shell --basic --quiet < session`
255+ Then STDOUT should be empty
256+
257+ Scenario: Normal mode shows return value
258+ Given a WP install
259+ And a session file:
260+ """
261+ $a = "hello" ;
262+ """
263+
264+ When I run `wp shell --basic < session`
265+ Then STDOUT should contain:
266+ """
267+ string(5) "hello"
268+ """
Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ class Shell_Command extends WP_CLI_Command {
5858 * # Start a shell, ensuring the 'init' hook has already fired.
5959 * $ wp shell --hook=init
6060 *
61+ * # Start a shell in quiet mode, suppressing return value output.
62+ * $ wp shell --quiet
63+ * wp> $a = "hello";
64+ * wp>
65+ *
6166 * @param string[] $_ Positional arguments. Unused.
6267 * @param array{basic?: bool, watch?: string} $assoc_args Associative arguments.
6368 */
@@ -109,6 +114,7 @@ private function start_shell( $assoc_args ) {
109114 }
110115
111116 $ class = WP_CLI \Shell \REPL ::class;
117+ $ quiet = (bool ) WP_CLI ::get_config ( 'quiet ' );
112118
113119 $ implementations = array (
114120 \Psy \Shell::class,
@@ -132,6 +138,9 @@ private function start_shell( $assoc_args ) {
132138 if ( \Psy \Shell::class === $ class ) {
133139 $ shell = new Psy \Shell ();
134140 $ shell ->run ();
141+ } elseif ( \Boris \Boris::class === $ class ) {
142+ $ boris = new \Boris \Boris ( 'wp> ' );
143+ $ boris ->start ();
135144 } else {
136145 /**
137146 * @var class-string<WP_CLI\Shell\REPL> $class
@@ -141,7 +150,7 @@ private function start_shell( $assoc_args ) {
141150 }
142151
143152 do {
144- $ repl = new $ class ( 'wp> ' );
153+ $ repl = new $ class ( 'wp> ' , $ quiet );
145154 if ( $ watch_path ) {
146155 $ repl ->set_watch_path ( $ watch_path );
147156 }
Original file line number Diff line number Diff line change @@ -10,14 +10,22 @@ class REPL {
1010
1111 private $ history_file ;
1212
13+ /** @var bool Whether to suppress automatic output. */
14+ private $ quiet ;
15+
1316 private $ watch_path ;
1417
1518 private $ watch_mtime ;
1619
1720 const EXIT_CODE_RESTART = 10 ;
1821
19- public function __construct ( $ prompt ) {
22+ /**
23+ * @param string $prompt Prompt to display.
24+ * @param bool $quiet Whether to suppress automatic output.
25+ */
26+ public function __construct ( $ prompt , $ quiet = false ) {
2027 $ this ->prompt = $ prompt ;
28+ $ this ->quiet = $ quiet ;
2129
2230 $ this ->set_history_file ();
2331 }
@@ -80,8 +88,11 @@ public function start() {
8088 if ( 0 < strlen ( $ __repl_output ) ) {
8189 echo rtrim ( $ __repl_output , "\n" ) . "\n" ;
8290 }
83- echo '=> ' ;
84- var_dump ( $ __repl_eval_result );
91+ ob_start ();
92+ if ( ! $ this ->quiet ) {
93+ echo '=> ' ;
94+ var_dump ( $ __repl_eval_result );
95+ }
8596 fwrite ( STDOUT , (string ) ob_get_clean () );
8697 }
8798 }
You can’t perform that action at this time.
0 commit comments