diff --git a/CHANGELOG.md b/CHANGELOG.md index 928d9f698..332d76639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Changed - `add()` now merges configuration options recursively [#962](https://github.com/deployphp/deployer/pull/962) - Added `writable_chmod_recursive` boolean option to enable non-recursive `chmod` +- `ask()` now supports autocomplete [#978](https://github.com/deployphp/deployer/pull/978) ## v4.1.0 [v4.0.2...v4.1.0](https://github.com/deployphp/deployer/compare/v4.0.2...v4.1.0) diff --git a/src/functions.php b/src/functions.php index df608db06..d8a3056f1 100644 --- a/src/functions.php +++ b/src/functions.php @@ -546,11 +546,16 @@ function has($name) /** * @param string $message * @param string|null $default + * @param string[]|null $suggestedChoices * @return string * @codeCoverageIgnore */ -function ask($message, $default = null) +function ask($message, $default = null, $suggestedChoices = null) { + if (($suggestedChoices !== null) && (empty($suggestedChoices))) { + throw new \InvalidArgumentException('Suggested choices should not be empty'); + } + if (isQuiet()) { return $default; } @@ -561,6 +566,10 @@ function ask($message, $default = null) $question = new Question($message, $default); + if (empty($suggestedChoices) === false) { + $question->setAutocompleterValues($suggestedChoices); + } + return $helper->ask(input(), output(), $question); }