Skip to content

Commit 36e50f9

Browse files
committed
Merge branch 'main' into copilot/add-suppress-output-option
2 parents 7a7031e + 6366639 commit 36e50f9

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

features/shell.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,44 @@ Feature: WordPress REPL
7878
history: -1: invalid option
7979
"""
8080
81+
Scenario: User can define variable named $line
82+
Given a WP install
83+
And a session file:
84+
"""
85+
$line = 'this should work';
86+
$line;
87+
"""
88+
89+
When I run `wp shell --basic < session`
90+
Then STDOUT should contain:
91+
"""
92+
=> string(16) "this should work"
93+
"""
94+
And STDOUT should contain:
95+
"""
96+
=> string(16) "this should work"
97+
"""
98+
99+
Scenario: User can define variables named $out and $evl
100+
Given a WP install
101+
And a session file:
102+
"""
103+
$out = 'out should work';
104+
$evl = 'evl should work';
105+
$out;
106+
$evl;
107+
"""
108+
109+
When I run `wp shell --basic < session`
110+
Then STDOUT should contain:
111+
"""
112+
=> string(15) "out should work"
113+
"""
114+
And STDOUT should contain:
115+
"""
116+
=> string(15) "evl should work"
117+
"""
118+
81119
Scenario: Shell with hook parameter
82120
Given a WP install
83121
And a session file:

src/WP_CLI/Shell/REPL.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,40 @@ public function __construct( $prompt, $quiet = false ) {
2727
public function start() {
2828
// @phpstan-ignore while.alwaysTrue
2929
while ( true ) {
30-
$line = $this->prompt();
30+
$__repl_input_line = $this->prompt();
3131

32-
if ( '' === $line ) {
32+
if ( '' === $__repl_input_line ) {
3333
continue;
3434
}
3535

36-
$line = rtrim( $line, ';' ) . ';';
36+
$__repl_input_line = rtrim( $__repl_input_line, ';' ) . ';';
3737

38-
if ( self::starts_with( self::non_expressions(), $line ) ) {
38+
if ( self::starts_with( self::non_expressions(), $__repl_input_line ) ) {
3939
ob_start();
4040
// phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval.
41-
eval( $line );
42-
$out = (string) ob_get_clean();
43-
if ( 0 < strlen( $out ) ) {
44-
$out = rtrim( $out, "\n" ) . "\n";
41+
eval( $__repl_input_line );
42+
$__repl_output = (string) ob_get_clean();
43+
if ( 0 < strlen( $__repl_output ) ) {
44+
$__repl_output = rtrim( $__repl_output, "\n" ) . "\n";
4545
}
46-
fwrite( STDOUT, $out );
46+
fwrite( STDOUT, $__repl_output );
4747
} else {
48-
if ( ! self::starts_with( 'return', $line ) ) {
49-
$line = 'return ' . $line;
48+
if ( ! self::starts_with( 'return', $__repl_input_line ) ) {
49+
$__repl_input_line = 'return ' . $__repl_input_line;
5050
}
5151

5252
// Write directly to STDOUT, to sidestep any output buffers created by plugins
5353
ob_start();
5454
// phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval.
55-
$evl = eval( $line );
56-
$out = (string) ob_get_clean();
57-
if ( 0 < strlen( $out ) ) {
58-
echo rtrim( $out, "\n" ) . "\n";
55+
$__repl_eval_result = eval( $__repl_input_line );
56+
$__repl_output = (string) ob_get_clean();
57+
if ( 0 < strlen( $__repl_output ) ) {
58+
echo rtrim( $__repl_output, "\n" ) . "\n";
5959
}
6060
ob_start();
6161
if ( ! $this->quiet ) {
6262
echo '=> ';
63-
var_dump( $evl );
63+
var_dump( $__repl_eval_result );
6464
}
6565
fwrite( STDOUT, (string) ob_get_clean() );
6666
}

0 commit comments

Comments
 (0)