Ask to user all needed information

@param  InputInterface  $input
@param  OutputInterface $output
@return array
197581
protected function getConnectionInfo(InputInterface $input, OutputInterface $output)
    {
        /** @var QuestionHelper $helper */
        $helper = $this->getHelper('question');

        $connectionInfo = array();

        $connectionInfo['host'] = $this->enterData(
            $helper,
            $input,
            $output,
            "Database host [default: localhost] : ",
            "You must specify a database host",
            false,
            "localhost"
        );

        $connectionInfo['port'] = $this->enterData(
            $helper,
            $input,
            $output,
            "Database port [default: 3306] : ",
            "You must specify a database port",
            false,
            "3306"
        );

        $connectionInfo['dbName'] = $this->enterData(
            $helper,
            $input,
            $output,
            "Database name (if database does not exist, Thelia will try to create it) : ",
            "You must specify a database name"
        );

        $connectionInfo['username'] = $this->enterData(
            $helper,
            $input,
            $output,
            "Database username : ",
            "You must specify a database username"
        );

        $connectionInfo['password'] = $this->enterData(
            $helper,
            $input,
            $output,
            "Database password : ",
            "You must specify a database username",
            true,
            null,
            true
        );

        return $connectionInfo;
    }
584800
protected function execute(InputInterface $input, OutputInterface $output)
  {
    $results = Cache::flush();

    if ($results) return $output->writeln('<info>Cleared cache!</info>');

    return $output->writeln('Nothing to clear');
  }
1055993
protected function systemStatus(InputInterface $input, OutputInterface $output)
    {
        // If no apps, trigger app:Add command.
        $helper = $this->getHelper('question');
        $apps = $this->getApplication()->getTerra()->getConfig()->get('apps');
        if (empty($apps)) {
            $output->writeln('You have no apps!');
            $question = new ConfirmationQuestion("Add an App? [y\N] ", false);
            if ($helper->ask($input, $output, $question)) {
                // Run environment:add command.
                $command = $this->getApplication()->find('app:add');
                $command->run($input, $output);
                return;
            }
        }

        // APPS table.
        $table = $this->getHelper('table');
        $table->setHeaders(array(
        'APPS',
        'Description',
        'Repo',
        'Environments',
        ));

        $rows = array();
        $options = array();
        foreach ($this->getApplication()
               ->getTerra()
               ->getConfig()
               ->get('apps') as $app) {

            $options[] = $app['name'];
            $row = array(
            $app['name'],
            $app['description'],
            $app['repo'],
            is_array($app['environments']) ? implode(', ', array_keys($app['environments'])) : 'None',
            );
            $rows[] = $row;
        }
        $table->setRows($rows);
        $table->render($output);

        $helper = $this->getHelper('question');
        $question = new Question('App? ');
        $question->setAutocompleterValues($options);
//
//        // Run app status
//        $name = $helper->ask($input, $output, $question);
//        if (empty($name)) {
//            return;
//        }
//        else {
//            // If an app name was chosen, run appStatus
//            $formatter = $this->getHelper('formatter');
//            $input->setArgument('app_name', $name);
//            $this->appStatus($input, $output);
//
//        }
    }
284393
public function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var QuestionHelper $helper */
        $helper = $this->getHelper('question');

        $copyrightYear = date('Y');
        $packageName = 'Unknown';
        $packageOwner = 'Contributors';
        $packageOwnerEmail = '';

        if ($input->hasOption('name')) {
            $packageName = $input->getOption('name');
        } else {
            $packageName = $helper->ask($input, $output, new Question(
                'What is the package name? '
            ));
        }

        if ($input->hasOption('owner')) {
            $packageOwner = $input->getOption('owner');
        } else {
            $packageOwner = $helper->ask($input, $output, new Question(
                'Who is the package owner? '
            ));
        }

        if ($input->hasOption('email')) {
            $packageOwnerEmail = $input->getOption('email');
        } else {
            $packageOwnerEmail = $helper->ask($input, $output, new Question(
                'What is the contact email of the owner? (Optional) ',
                ''
            ));
        }

        $template = file_get_contents(
            __DIR__ . '/../../../../resources/project/formatter.yml'
        );

        $template = str_replace('<year>', $copyrightYear, $template);
        $template = str_replace('<owner>', $packageOwner, $template);
        $template = str_replace('<package>', $packageName, $template);
        $template = str_replace('<email>', $packageOwnerEmail, $template);

        $filesystem = new Filesystem();

        if ($filesystem->exists('.formatter.yml')) {
            if ($helper->ask($input, $output, new ConfirmationQuestion(
                '.formatter.yml already exists. Overwrite? (y/N) ',
                false
            ))) {
                $filesystem->dumpFile('.formatter.yml', $template);
                $output->writeln('Wrote .formatter.yml');
            }
        } else {
            $filesystem->dumpFile('.formatter.yml', $template);
            $output->writeln('Wrote .formatter.yml');
        }

        if (!$filesystem->exists('.editorconfig')) {
            $filesystem->dumpFile(
                '.editorconfig',
                file_get_contents(
                    __DIR__ . '/../../../../resources/project/editorconfig'
                )
            );
            $output->writeln('Wrote .editorconfig');
        }

        return 0;
    }
261749
private function askForAnotherAclRule(InputInterface $input, OutputInterface $output) {
        return $this->getHelper('question')->ask($input, $output, new ConfirmationQuestion(
            'Create more ACL-rules for this public key? (y/N) ',
            false
        ));
    }
711042
protected function executeValidation(InputInterface $input, OutputInterface $output)
    {
        $types = [];

        foreach ($this->getResolver()->getTypes() as $type) {
            $types[$type->getType()] = $type->getType();
        }

        $invalid = [];

        foreach ($input->getArgument('id') as $id) {
            if (!isset($types[$id])) {
                $invalid[] = $id;
            }
        }

        if ($invalid) {
            $text = sprintf('The content types "%s" do not exists', implode(', ', $invalid));

            if ($input->getOption('no-interaction')) {
                throw new InvalidArgumentException($text);
            }

            // ask the user if he/she want to continue or not.

            $output->writeln($text);

            if (!$this->getQuestion()->ask(
                $input,
                $output,
                new ConfirmationQuestion('Would you want to continue? [y/N] ', false)
            )) {
                return 1;
            }
        }

        return 0;
    }
174434
protected function execute(InputInterface $input, Output\OutputInterface $output)
    {
        foreach ($this->getDefinition()->getArguments() as $arg) {
            if ($arg->getName() === 'command') {
                continue;
            }
            if ($input->getArgument($arg->getName())) {
                $this->getContainer()->set(explode('.', $this->nameToVar($arg->getName())), $input->getArgument($arg->getName()));
            }
        }

        foreach ($this->opts as $opt) {
            if ($value = $input->getOption($this->varToName($opt))) {
                $this->getContainer()->set(explode('.', $opt), $value);
            }
        }

        foreach ($this->flags as $name => $value) {
            $varName = explode('.', $name);
            $optName = $this->varToName($name);
            $this->getContainer()->set($varName, $value);

            if ($input->getOption('no-' . $optName) && $input->getOption($optName)) {
                throw new \InvalidArgumentException("Conflicting options --no-{$optName} and --{$optName} supplied. That confuses me.");
            }
            if ($input->getOption('no-' . $optName)) {
                $this->getContainer()->set($varName, false);
            } elseif ($input->getOption($optName)) {
                $this->getContainer()->set($varName, true);
            }
        }

        $callable = $this->getContainer()->get($this->getTaskReference());
        call_user_func($callable, $this->getContainer());
    }
198861
public function ask(InputInterface $input, OutputInterface $output, Question $question)
    {
        if ($output instanceof ConsoleOutputInterface) {
            $output = $output->getErrorOutput();
        }

        if (!$input->isInteractive()) {
            $default = $question->getDefault();

            if (null === $default) {
                return $default;
            }

            if ($validator = $question->getValidator()) {
                return \call_user_func($question->getValidator(), $default);
            } elseif ($question instanceof ChoiceQuestion) {
                $choices = $question->getChoices();

                if (!$question->isMultiselect()) {
                    return isset($choices[$default]) ? $choices[$default] : $default;
                }

                $default = explode(',', $default);
                foreach ($default as $k => $v) {
                    $v = trim($v);
                    $default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
                }
            }

            return $default;
        }

        if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
            $this->inputStream = $stream;
        }

        if (!$question->getValidator()) {
            return $this->doAsk($output, $question);
        }

        $interviewer = function () use ($output, $question) {
            return $this->doAsk($output, $question);
        };

        return $this->validateAttempts($interviewer, $output, $question);
    }
10580
protected function execute(InputInterface $input, OutputInterface $output)
	{
		$output->writeln([ // outputs multiple lines to the console (adding "\n" at the end of each line)
			'MyAdmin DocBlock Parser',
			'=======================',
			''
						 ]);
		$output->writeln('<info>foo</info>'); // green text
		$output->writeln('<comment>foo</comment>'); // yellow text
		$output->writeln('<question>foo</question>'); // black text on a cyan background
		$output->writeln('<error>foo</error>'); // white text on a red background
		$formatter = $this->getHelper('formatter');
		// Section - [SomeSection] Here is some message related to that section
		$formattedLine = $formatter->formatSection('SomeSection', 'Here is some message related to that section');
		$output->writeln($formattedLine);
		// Error Block
		$errorMessages = ['Error!', 'Something went wrong'];
		$formattedBlock = $formatter->formatBlock($errorMessages, 'error');
		$output->writeln($formattedBlock);

		$paths = ['include', 'scripts'];
		$calls = [
			'getFiles'      => ['getHash', 'getSource', 'getNamespaces', 'getIncludes', 'getConstants', 'getFunctions', 'getInterfaces', 'getTraits', 'getPath', 'getDocBlock', 'getName'],
			'getNamespaces' => ['getClasses', 'getConstants', 'getFunctions', 'getInterfaces', 'getTraits', 'getFqsen', 'getName'],
			'getClasses'    => ['isFinal', 'isAbstract', 'getParent', 'getInterfaces', 'getConstants', 'getMethods', 'getProperties', 'getUsedTraits', 'getFqsen', 'getName', 'getDocBlock'],
			'getMethods'    => ['isAbstract', 'isFinal', 'isStatic', 'getVisibility', 'getArguments', 'getFqsen', 'getName', 'getDocBlock'],
			'getProperties' => ['isStatic', 'getDefault', 'getTypes', 'getVisibility', 'getFqsen', 'getName', 'getDocBlock'],
			'getTraits'     => ['getMethods', 'getProperties', 'getUsedTraits', 'getFqsen', 'getName', 'getDocBlock'],
			'getInterfaces' => ['getParents', 'getConstants', 'getMethods', 'getFqsen', 'getName', 'getDocBlock'],
			'getArguments'  => ['isByReference', 'isVariadic', 'getName', 'getTypes', 'getDefault'],
			'getFunctions'  => ['getArguments', 'getFqsen', 'getName', 'getDocBlock'],
			'getConstants'  => ['getValue', 'getFqsen', 'getName', 'getDocBlock']
		];
		/**
		 * @param $parent
		 * @param $call
		 * @param $calls
		 * @return array
		 */
		function do_call($parent, $call, $calls)
		{
			echo "Running \$parent->$call();".PHP_EOL;
			$response = $parent->$call();
			if (isset($calls[$call])) {
				$out = [];
				/** @var \phpDocumentor\Reflection\Php\File $file */
				foreach ($response as $idx => $child) {
					foreach ($calls[$call] as $childCall) {
						/** @var \phpDocumentor\Reflection\Php\File $file */
						$out[$idx] = $childResponse = $child->$childCall();
					}
				}
				echo "Running \$child->$childCall();".PHP_EOL;
				return $out;
			} else {
				return $response;
			}
		}

		$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();
		$files = [];
		$map = [];
		foreach ($paths as $path) {
			$files[] = new \phpDocumentor\Reflection\File\LocalFile(__DIR__.'/../../../../../'.$path);
		}
		/** @var Project $project */
		$project = $projectFactory->create('MyProject', $files);
		$map = do_call($project, 'getFiles', $calls);
		file_put_contents(__DIR__.'/../../../../../include/config/parse.serial', serialize($map));
		file_put_contents(__DIR__.'/../../../../../include/config/parse.json', json_encode($map, JSON_PRETTY_PRINT));
		/** @var \phpDocumentor\Reflection\Php\Class_ $class */
		/* foreach ($file->getClasses() as $class)
			echo '- ' . $class->getFqsen() . PHP_EOL;
		} */
		/** @var \phpDocumentor\Reflection\Php\Function_ $function */
		/* foreach ($file->getFunctions() as $function) {
			echo '- ' . $function->getFqsen() . PHP_EOL;
		} */

		/** DocBlock / Reflection Parsing
		 * Reconstituting a docblock - https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/examples/03-reconstituting-a-docblock.php
		 * Adding Your own Tag - https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/examples/04-adding-your-own-tag.php
		 */

		/*
		$class = new ReflectionClass('MyClass');
		$phpdoc = new \phpDocumentor\Reflection\DocBlock($class);

		var_dump($phpdoc->getShortDescription());
		var_dump($phpdoc->getLongDescription()->getContents());
		var_dump($phpdoc->getTags());
		var_dump($phpdoc->hasTag('author'));
		var_dump($phpdoc->hasTag('copyright'));
		// But we can also grab all tags of a specific type, such as `see`
		$seeTags = $docblock->getTagsByName('see');

		$reflector = new ReflectionClass('Example');
		// to get the Class DocBlock
		echo $reflector->getDocComment();
		// to get the Method DocBlock
		$reflector->getMethod('fn')->getDocComment();
		*/
	}
342961
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->cacheService->system()->clear();
        $this->cacheService->user()->clear();
        $output->writeln('Done!');
        return null;
    }
413362
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $actions = new Finder(APP_PATH, 'One\\Context\\Contracts\\Action', 'php');

        foreach ($actions as $action) {
            $this->output('Action', 'info', $action->getBasename('.php'), '');
        }
    }
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>');
    }
893976
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Available templates:');
        foreach ($this->factory->getAllNames() as $template_name) {
            $output->writeln('* '.$template_name);
        }
        $output->writeln('');
    }
767543
protected function getRepositoryAndIndices(
        InputInterface $input,
        OutputInterface $output
    ): array {
        $appName = $input->getArgument('app-name');
        $configuration = $this->repositoryBucket->getConfiguration();

        if (!isset($configuration[$appName])) {
            throw new Exception(sprintf('App %s not found under apisearch configuration', $appName));
        }

        $appId = $configuration[$appName]['app_id'];
        self::printInfoMessage(
            $output,
            $this->getHeader(),
            "App: <strong>{$appName} / {$appId}</strong>"
        );

        if (!$input->hasOption('index-name')) {
            return [$configuration[$appName]['app_id'], []];
        }

        $indexNamesAsArray = $configuration[$appName]['indices'] ?? [];

        $indices = array_map(function (string $indexName) use ($indexNamesAsArray, $appName, $output) {
            if (!isset($indexNamesAsArray[$indexName])) {
                throw new Exception(sprintf(
                    'Index %s not found under %s repository. Indices availables: %s',
                    $indexName,
                    $appName,
                    implode(', ', array_keys($indexNamesAsArray))
                ));
            }

            $indexId = $indexNamesAsArray[$indexName];
            self::printInfoMessage(
                $output,
                $this->getHeader(),
                "Index: <strong>{$indexName} / {$indexId}</strong>"
            );

            return IndexUUID::createById($indexId);
        }, $input->getOption('index-name'));

        return [
            AppUUID::createById($appId),
            $indices,
        ];
    }
250466
protected function getPassword(InputInterface $input, OutputInterface $output): ?string
    {
        $password = $input->getOption('password');
        if (null === $password && $input->isInteractive()) {
            $message = $this->translator->trans('user.blank_password_info', [], 'security');
            $output->writeln("<info>{$message}</info>");
            /** @var QuestionHelper $questionHelper */
            $questionHelper = $this->getHelper('question');
            $question = new Question(
                "<info>{$this->translator->trans('admin.user.form.password.label')}: </info>"
            );
            $question->setHidden(true);
            $password = (string) $questionHelper->ask($input, $output, $question);
        }

        return $password;
    }
1239157
private function askForPrivateKey(InputInterface $input, OutputInterface $output) {
        $privateKeyGenerator = new GeneratePrivateKey();

        $question = new Question(
            'What do you want the private key to be (leave blank to generate)',
            $privateKeyGenerator->generate()
        );

        return $this->getHelper('question')->ask($input, $output, $question);
    }
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),
            '',
        ]);
    }