diff --git a/features/shell.feature b/features/shell.feature index 301c61bc..d5595506 100644 --- a/features/shell.feature +++ b/features/shell.feature @@ -60,3 +60,20 @@ Feature: WordPress REPL bool(true) """ And STDERR should be empty + + Scenario: Input starting with dash + Given a WP install + And a session file: + """ + -1 + """ + + When I run `wp shell --basic < session` + Then STDOUT should contain: + """ + int(-1) + """ + And STDERR should not contain: + """ + history: -1: invalid option + """ diff --git a/src/WP_CLI/Shell/REPL.php b/src/WP_CLI/Shell/REPL.php index 15697bf0..99b8f1f8 100644 --- a/src/WP_CLI/Shell/REPL.php +++ b/src/WP_CLI/Shell/REPL.php @@ -137,7 +137,7 @@ private static function create_prompt_cmd( $prompt, $history_path ) { . 'LINE=""; ' . "read -re -p {$prompt} LINE; " . '[ $? -eq 0 ] || exit; ' - . 'history -s "$LINE"; ' + . 'history -s -- "$LINE"; ' . "history -w {$history_path}; " . 'echo $LINE; ';