Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Fix #21789 : CLI Windows autcompletion for ChoiceQuestion function #24716

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

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 21 additions & 0 deletions src/Symfony/Component/Console/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ abstract class Helper implements HelperInterface
{
protected $helperSet = null;

const OS_UNKNOWN = 1;
const OS_WIN = 2;
const OS_LINUX = 3;
const OS_OSX = 4;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -121,4 +126,20 @@ public static function removeDecoration(OutputFormatterInterface $formatter, $st

return $string;
}

/**
* GET Os Terminal to define CLI's behavior
* Used especially for autocompletion.
*
* @return string
*/
public function getOSTerminal()
{
switch (true) {
case stristr(PHP_OS, 'DAR'): return self::OS_OSX;
Copy link
Member

@keradus keradus Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this code gonna survive as private method:
PHP_OS_FAMILY could be better choice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On PHP 5.3?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't Sf use it's own polyfill ?

case stristr(PHP_OS, 'WIN'): return self::OS_WIN;
case stristr(PHP_OS, 'LINUX'): return self::OS_LINUX;
default: return self::OS_UNKNOWN;
}
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function doAsk(OutputInterface $output, Question $question)
$inputStream = $this->inputStream ?: STDIN;
$autocomplete = $question->getAutocompleterValues();

if (null === $autocomplete || !$this->hasSttyAvailable()) {
if ((null === $autocomplete || self::OS_WIN == $this->getOSTerminal()) || !$this->hasSttyAvailable()) {
Copy link
Member

@nicolas-grekas nicolas-grekas Oct 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding new const + public method is a new feature.
Here, it's not needed, just do as we do everywhere else: '\\' === \DIRECTORY_SEPARATOR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or use a private method here instead of putting this in the base Helper class

$ret = false;
if ($question->isHidden()) {
try {
Expand Down