This method ensure that we stay compatible with symfony console 2.3 by using the deprecated dialog helper
but use the ConfirmationQuestion when available.

@param $question
@param InputInterface $input
@param OutputInterface $output
@return mixed
331940
protected function askConfirmation($question, InputInterface $input, OutputInterface $output) {
        if (!$this->getHelperSet()->has('question')) {
            return $this->getHelper('dialog')
                ->askConfirmation($output, '<question>' . $question . '</question>', 'y');
        }

        return $this->getHelper('question')
            ->ask($input, $output, new \Symfony\Component\Console\Question\ConfirmationQuestion($question));
    }
245680
protected function checkComposer(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
    {
        $question = new Question('<info>Download composer</info> [<comment>yes</comment>]: ', 'yes');
        $question->setAutocompleterValues(['yes', 'no']);
        $downloadComposer = $questionHelper->ask($input, $output, $question);
        $deployData['composer'] = $downloadComposer == 'yes' ? true : false;

        return $deployData['composer'];
    }
64469
protected function ask($question, $default = null)
    {
        $defaultComment = '';
        
        if ($default !== null) {
            $defaultComment = ' [<comment>' . $default . '</comment>]';
        }
        
        $question = preg_replace('/(?:(\?)\s*$|(\?)?\s+$)|(?<!\s|\?)$/', $defaultComment . '$1 ', $question);
        
        return $this->io->ask($question, $default);
    }
994329
public function askThenRemove(InputInterface $input, OverwritableOutputInterface $output, Question $question)
    {
        // Following suit of ask().
        if (!$input->isInteractive()) {
            return $question->getDefault();
        }

        $this->remove = true;
        $this->question = $question;
        $this->output = $output;
        $this->autocomplete = $this->question->getAutocompleterValues() !== null && $this->hasSttyAvailable();

        $this->output->capture();

        // Wrap normalizer to remove latest question & answer since
        // it is called for each iteration if answer is not valid.
        $normalizer = $question->getNormalizer();
        $question->setNormalizer(function ($value) use ($normalizer) {
            $this->output->remove();
            $this->output->capture();

            if (is_callable($normalizer)) {
                return $normalizer($value);
            }

            return $value;
        });

        try {
            $value = $this->ask($input, $this->output, $question);
        } finally {
            $this->remove = false;
            $this->question = null;
            $this->output->remove();
            $this->output = null;
        }

        return $value;
    }
244475
private function askIfContinueToAdd(
        HelperSet $helperSet,
        InputInterface $input,
        OutputInterface $output
    ) {
        return $this->questionHelper($helperSet)->ask(
            $input,
            $output,
            new ConfirmationQuestion(
                Format::forQuestion('Add another entry to this collection?', 'n'),
                false
            )
        );
    }
183925
protected function interact(InputInterface $input, OutputInterface $output)
    {
        $questionHelper = $this->getQuestionHelper();
        $questionHelper->writeSection($output, 'Welcome to the Victoire widget bundle generator');

        ///////////////////////
        //                   //
        //   Create Bundle   //
        //                   //
        ///////////////////////

        // namespace
        $namespace = null;

        try {
            $namespace = $input->getOption('namespace') ? Validators::validateBundleNamespace($input->getOption('namespace')) : null;
        } catch (\Exception $error) {
            $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
        }

        if (null === $namespace) {
            $output->writeln([
                '',
                'Your application code must be written in <comment>widget bundles</comment>. This command helps',
                'you generate them easily.',
                '',
                'Each widget is hosted under a namespace (like <comment>Victoire/Widget/YourAwesomeWidgetNameBundle</comment>).',
                '',
                'If you want for example a BlogWidget, the Widget Name should be Blog',
            ]);

            $question = new Question($questionHelper->getQuestion('Widget name', $input->getOption('bundle-name')));
            $question->setValidator(function ($answer) {
                return self::validateWidgetName($answer, false);
            });

            $name = $questionHelper->ask(
                $input,
                $output,
                $question
            );

            $bundle = 'VictoireWidget'.$name.'Bundle';
            $input->setOption('bundle-name', $bundle);
            $namespace = 'Victoire\\Widget\\'.$name.'Bundle';
            $input->setOption('namespace', $namespace);
        }

        $orgname = $input->getOption('orgname');

        if (null === $orgname) {
            $output->writeln([
                '',
                'A composer.json file will be generated, we need to know under which organisation you will publish the widget',
                '',
                'The default organisation will be friendsofvictoire',
            ]);
            $question = new Question($questionHelper->getQuestion('Under which organisation do you want to publish your widget ?', 'friendsofvictoire'), 'friendsofvictoire');

            $orgname = $questionHelper->ask($input, $output, $question);
        }

        $input->setOption('orgname', $orgname);

        $parent = $input->getOption('parent');

        $question = new ConfirmationQuestion($questionHelper->getQuestion('Does your widget extends another widget ?', 'no', '?'), false);

        if (null === $parent && $questionHelper->ask($input, $output, $question)) {
            $output->writeln([
                '',
                'A widget can extends another to reproduce its behavior',
                '',
                'If you wabt to do so, please give the name of the widget to extend',
                '',
                'If you want to extends the TestWidget, the widget name should be Test',
            ]);

            $question = new Question($questionHelper->getQuestion('Parent widget name', false));
            $question->setValidator(function ($answer) {
                return self::validateWidgetName($answer, false);
            });
            $parent = $questionHelper->ask($input, $output, $question);

            $input->setOption('parent', $parent);

            $packagistParentName = 'friendsofvictoire/'.strtolower($parent).'-widget';
            $question = new Question($questionHelper->getQuestion('Parent widget packagist name', $packagistParentName));

            $parent = $questionHelper->ask($input, $output, $question);

            $input->setOption('packagist-parent-name', $packagistParentName);
        }

        $dir = dirname($this->getContainer()->getParameter('kernel.root_dir')).'/src';

        $output->writeln([
            '',
            'The bundle can be generated anywhere. The suggested default directory uses',
            'the standard conventions.',
            '',
        ]);

        $question = new Question($questionHelper->getQuestion('Target directory', $dir), $dir);
        $question->setValidator(function ($dir) use ($bundle, $namespace) {
            return Validators::validateTargetDir($dir, $bundle, $namespace);
        });
        $dir = $questionHelper->ask($input, $output, $question);
        $input->setOption('dir', $dir);

        // format
        $format = null;

        try {
            $format = $input->getOption('format') ? Validators::validateFormat($input->getOption('format')) : null;
        } catch (\Exception $error) {
            $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
        }

        if (null === $format) {
            $output->writeln([
                '',
                'Determine the format to use for the generated configuration.',
                '',
            ]);

            $question = new Question($questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', 'annotation'), 'annotation');
            $question->setValidator(
                ['Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateFormat']
            );
            $format = $questionHelper->ask($input, $output, $question);
            $input->setOption('format', $format);
        }

        $input->setOption('structure', false);

        $contentResolver = $input->getOption('content-resolver');

        $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to customize widget rendering logic ?', 'no', '?'), false);
        if (!$contentResolver && $questionHelper->ask($input, $output, $question)) {
            $contentResolver = true;
        }
        $input->setOption('content-resolver', $contentResolver);

        ///////////////////////
        //                   //
        //   Create Entity   //
        //                   //
        ///////////////////////

        $input->setOption('fields', $this->addFields($input, $output, $questionHelper));
        $entity = 'Widget'.$name;
        $input->setOption('entity', $bundle.':'.$entity);

        $cache = $input->getOption('cache');
        $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want use cache for this widget ?', 'no', '?'), false);
        if (null !== $cache) {
            $cache = $questionHelper->ask($input, $output, $question);
        }
        $input->setOption('cache', $cache);

        // summary
        $output->writeln([
            '',
            $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true),
            '',
            sprintf("You are going to generate a \"<info>%s\\%s</info>\" widget bundle\nin \"<info>%s</info>\" using the \"<info>%s</info>\" format.", $namespace, $bundle, $dir, $format),
            '',
        ]);
    }
1128702
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $plugin = $input->getArgument('plugin');

        $pluginExp = explode('/', $plugin);

        $packageDir = config_path().'/'.$pluginExp[0];
        $configFile = $pluginExp[1].'.php';

        if (!file_exists($packageDir)) {
            $publish = true;
        } else {
            $helper = $this->getHelper('question');
            $question = new ConfirmationQuestion(
                "$plugin already has a config script in place, are you sure you want to overwrite it? ",
                false,
                '/^yes|y/i'
            );

            $publish = $helper->ask($input, $output, $question);
        }

        if ($publish) {
            mkdir($packageDir);
            $pluginConfig = app_path().'/../vendor/'.$plugin.'/config.php';
            $publishConfig = $packageDir.'/'.$configFile;

            $file = fopen($pluginConfig, 'r');
            $content = fread($file, filesize($pluginConfig));
            fclose($file);

            $file = fopen($publishConfig, 'w');
            fwrite($file, $content);
            fclose($file);

            $output->writeln("<info>Configuration for $plugin published</info>");
        }
    }
1026910
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$this->apiHelper->restore($this->getHelper('question'), $input, $output)) {
            return;
        }

        $bunqUser = $this->apiHelper->currentUser()->getBunqUser();

        /** @var Pointer $pointer */
        foreach ($bunqUser->getAlias() as $pointer) {
            $output->writeln(\sprintf('<info>%s</info>: %s', $pointer->getType(), $pointer->getValue()));
        }
    }
893083
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->setManagerFactory($this->getContainer()->get('symfonyid.admin.manager.manager_factory'));
        $questionHelper = $this->getQuestionHelper();

        $this->interactive($input, $output);

        $forceOverwrite = $input->getOption('overwrite');
        $onlyForm = $input->getOption('only-form');
        $onlyController = $input->getOption('only-controller');
        if ($model = $input->getArgument('model')) {
            $this->generate($output, $model, $forceOverwrite);
        } else {
            if ($input->isInteractive()) {
                $question = new ConfirmationQuestion($questionHelper->getQuestion('Are you sure generate crud from all models', 'yes', '?'), true);
                if (!$questionHelper->ask($input, $output, $question)) {
                    $output->writeln('<error>Command aborted</error>');

                    return 1;
                }
            }

            $bundles = $this->getContainer()->getParameter('symfonyid.admin.bundles');
            foreach ($bundles as $bundle) {
                $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);

                $finder = new Finder();
                $finder->name('*.php')->in(array($bundle->getPath().'/Entity', $bundle->getPath().'/Document'));

                $this->findModelAndGenerate($finder, $bundle, $output, $forceOverwrite, $onlyForm, $onlyController);
            }
        }

        /** @var KernelInterface $kernel */
        $kernel = $this->getContainer()->get('kernel');
        $cacheClearCommand = $this->getApplication()->find('cache:clear');
        $cacheClearCommand->run(new ArrayInput(array('--env' => $kernel->getEnvironment())), $output);

        $output->writeln('<info>CRUD Generation is successfully!</info>');
    }
827898
public function ask($question, $verbosity = null, $default = null, array $args = [])
    {
        $message    =   $this->interpolate($question, $args);
        return parent::ask($message, $default);
    }
311101
private function autocomplete(OutputInterface $output, Question $question, $inputStream)
    {
        $autocomplete = $question->getAutocompleterValues();
        $ret = '';

        $i = 0;
        $ofs = -1;
        $matches = $autocomplete;
        $numMatches = count($matches);

        $sttyMode = shell_exec('stty -g');

        // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
        shell_exec('stty -icanon -echo');

        // Add highlighted text style
        $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));

        // Read a keypress
        while (!feof($inputStream)) {
            $c = fread($inputStream, 1);

            // Backspace Character
            if ("\177" === $c) {
                if (0 === $numMatches && 0 !== $i) {
                    --$i;
                    // Move cursor backwards
                    $output->write("\033[1D");
                }

                if ($i === 0) {
                    $ofs = -1;
                    $matches = $autocomplete;
                    $numMatches = count($matches);
                } else {
                    $numMatches = 0;
                }

                // Pop the last character off the end of our string
                $ret = substr($ret, 0, $i);
            } elseif ("\033" === $c) {
                // Did we read an escape sequence?
                $c .= fread($inputStream, 2);

                // A = Up Arrow. B = Down Arrow
                if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
                    if ('A' === $c[2] && -1 === $ofs) {
                        $ofs = 0;
                    }

                    if (0 === $numMatches) {
                        continue;
                    }

                    $ofs += ('A' === $c[2]) ? -1 : 1;
                    $ofs = ($numMatches + $ofs) % $numMatches;
                }
            } elseif (ord($c) < 32) {
                if ("\t" === $c || "\n" === $c) {
                    if ($numMatches > 0 && -1 !== $ofs) {
                        $ret = $matches[$ofs];
                        // Echo out remaining chars for current match
                        $output->write(substr($ret, $i));
                        $i = strlen($ret);
                    }

                    if ("\n" === $c) {
                        $output->write($c);
                        break;
                    }

                    $numMatches = 0;
                }

                continue;
            } else {
                $output->write($c);
                $ret .= $c;
                ++$i;

                $numMatches = 0;
                $ofs = 0;

                foreach ($autocomplete as $value) {
                    // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
                    if (0 === strpos($value, $ret) && $i !== strlen($value)) {
                        $matches[$numMatches++] = $value;
                    }
                }
            }

            // Erase characters from cursor to end of line
            $output->write("\033[K");

            if ($numMatches > 0 && -1 !== $ofs) {
                // Save cursor position
                $output->write("\0337");
                // Write highlighted text
                $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
                // Restore cursor position
                $output->write("\0338");
            }
        }

        // Reset stty so it behaves normally again
        shell_exec(sprintf('stty %s', $sttyMode));

        return $ret;
    }
189224
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$this->apiHelper->restore($this->getHelper('question'), $input, $output)) {
            return;
        }

        $output->writeln(\sprintf('Checking for URL: <info>%s</info>', $this->getUrl()).PHP_EOL);

        /** @var QuestionHelper $asker */
        $asker = $this->getHelper('question');
        $user = $this->apiHelper->currentUser();

        $enabled = $this->getCallbackStatus($user);
        $question = new ConfirmationQuestion(
            sprintf(
                '%s [y/N]: ',
                $enabled
                    ? 'The callback is currently <info>ACTIVE</info>, would you like to disable?'
                    : 'The callback is currently <info>INACTIVE</info>, would you like to enable?'
            ),
            false
        );

        if (!$asker->ask($input, $output, $question)) {
            return;
        }

        try {
            if ($enabled) {
                $this->disableCallback($user);
            } else {
                $this->enableCallback($user);
            }

            $output->writeln('<info>New status successfully applied.</info>');
        } catch (BunqException $exception) {
            $output->writeln('<error>An error occured while applying new status: '.$exception->getMessage().'</error>');
        }
    }
1370801
private function askForFieldName(InputInterface $input, OutputInterface $output, QuestionHelper $dialog, $fields)
    {
        $question = new Question($dialog->getQuestion('New field name (press <return> to stop adding fields)', null));
        $question->setValidator(function ($name) use ($fields) {
            if (isset($fields[$name]) || 'id' == $name) {
                throw new \InvalidArgumentException(sprintf('Field "%s" is already defined.', $name));
            }

            return $name;
        });

        return $dialog->ask($input, $output, $question);
    }
69039
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;

        /** @var $repository Repository */
        $repository = $this->getContainer()->get('ezpublish.api.repository');

        /** @var $contentTypeService ContentTypeService */
        $contentTypeService = $repository->getContentTypeService();
        /** @var $contentLanguageService LanguageService */
        $contentLanguageService = $repository->getContentLanguageService();

        /** @var $questionHelper QuestionHelper */
        $questionHelper = $this->getHelper('question');

        $struct = array();

        $struct['contentTypeGroup'] = $this->getContentTypeGroup($contentTypeService, $questionHelper);
        $struct['contentTypeIdentifier'] = $this->getContentTypeIdentifier($questionHelper);
        $struct['contentTypeName'] = $this->getContentTypeName($questionHelper);
        $struct['contentTypeMainLanguage'] = $this->getContentTypeMainLanguage($contentLanguageService, $questionHelper);
        $struct['contentTypeNameSchema'] = $this->getContentTypeNameSchema($questionHelper);
        $struct['fields'] = array();

        while (true) {
            $struct['fields'][] = $this->getContentTypeField($questionHelper, $struct['contentTypeMainLanguage']);
            $question = new ConfirmationQuestion(
                '<question>Do you want to add new field?</question> ',
                false
            );

            if (!$questionHelper->ask($input, $output, $question)) {
                $output->writeln('');
                break;
            }
        }

        /** @var $configResolver ConfigResolver */
        $configResolver = $this->getContainer()->get('ezpublish.config.resolver');
        $adminID = $configResolver->getParameter('adminid', 'smile_ez_tools');

        $contentTypeService = new ContentType($repository);
        $contentTypeService->setAdminID($adminID);
        try {
            $contentTypeService->add($struct);
            $output->writeln("<info>Content type created</info>");
        } catch (UnauthorizedException $e) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        } catch (ForbiddenException $e ) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        }
    }
1224456
protected function interact(InputInterface $input, OutputInterface $output)
    {
        $questionHelper = $this->getHelper('question');
        $formatter = $this->getHelper('formatter');
        $rootDir = $this->getRootDir();
        $fs = new Filesystem();
        $appPath = explode('/', $rootDir);
        $appName = $appPath[count($appPath) - 2];

        $this->initConfig($fs, $rootDir);
        $output->writeln([$formatter->formatSection('SETUP', 'Project settings'), '']);

        $deployData = $this->configureDeploy($input, $output, $questionHelper, $appName);
        $deploy = new DeployGenerator($deployData, $rootDir);
        $this->generate($deploy);

        $output->writeln(['', " > generating <comment>{$appName}/config/deploy.rb</comment>"]);
        $output->writeln(['<info>Successfully created.</info>', '']);
        $output->writeln([$formatter->formatSection('PRODUCTION', 'Remote server / SSH settings'), '']);

        $sshProps = $this->configureSSH($input, $output, $questionHelper, $deployData);
        $staging = new StagingGenerator($sshProps, $this->getCapistranoDeployDir());
        $yamlStaging = new YamlStagingGenerator($sshProps, $this->getStagingsConfigDir());

        $this->generateMany([$staging, $yamlStaging]);

        return $output->writeln('<comment>Remote server successfully configured</comment>');
    }
930523
public function ask($question, $default = null)
    {
        $question = new Question("<question>$question</question> ", $default);

        return $this->helper('question')->ask($this->input, $this->output, $question);
    }
9610
public function ask($question, $default = null)
	{
		$dialog = $this->getHelperSet()->get('dialog');

		return $dialog->ask($this->output, "<question>$question</question>", $default);
	}