Skip to content

Commit cf0435a

Browse files
Copilotswissspidy
andcommitted
Fix history command to handle input starting with dash
Co-authored-by: swissspidy <[email protected]>
1 parent 6565922 commit cf0435a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

features/shell.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ Feature: WordPress REPL
6060
bool(true)
6161
"""
6262
And STDERR should be empty
63+
64+
Scenario: Input starting with dash
65+
Given a WP install
66+
And a session file:
67+
"""
68+
-1
69+
"""
70+
71+
When I run `wp shell --basic < session`
72+
Then STDOUT should contain:
73+
"""
74+
int(-1)
75+
"""
76+
And STDERR should not contain:
77+
"""
78+
history: -1: invalid option
79+
"""

src/WP_CLI/Shell/REPL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static function create_prompt_cmd( $prompt, $history_path ) {
137137
. 'LINE=""; '
138138
. "read -re -p {$prompt} LINE; "
139139
. '[ $? -eq 0 ] || exit; '
140-
. 'history -s "$LINE"; '
140+
. 'history -s -- "$LINE"; '
141141
. "history -w {$history_path}; "
142142
. 'echo $LINE; ';
143143

0 commit comments

Comments
 (0)