Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable autocomplete for ask() #978

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down