<commit_before><?php

namespace vierbergenlars\CliCentral\Command\Config;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use vierbergenlars\CliCentral\Exception\Configuration\MissingConfigurationParameterException;
use vierbergenlars\CliCentral\Exception\File\FileException;
use vierbergenlars\CliCentral\Exception\File\FileExistsException;
use vierbergenlars\CliCentral\FsUtil;
use vierbergenlars\CliCentral\Helper\GlobalConfigurationHelper;

class InitCommand extends Command
{
    protected function configure()
    {
        $this->setName('config:init')
            ->addOption('no-create-missing', null, InputOption::VALUE_NONE, 'Do not create missing directories')
            ->setDescription('Initialize configuration')
            ->setHelp(<<<'EOF'
The <info>%command.name%</info> command presents a guide to do the initial configuration.
This command will ask interactive questions, unless <comment>--no-interaction|-n</comment> is used.

  <info>%command.full_name%</info>

It will help you to set up the configuration values <comment>applications-dir</comment>, <comment>vhosts-dir</comment>
and <comment>ssh-dir</comment>.

Non-existing directories will automatically be created, unless the <comment>--no-create-missing</comment> option is used.

This command can only be used to create the initial configuration file, it cannot be used to change configuration parameters.

To read configuration parameters, use the <info>config:get</info> command.
To set configuration parameters, use the <info>config:set</info> command.
To remove configuration parameters, use the <info>config:unset</info> command.
EOF
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $configHelper = $this->getHelper('configuration');
        /* @var $configHelper GlobalConfigurationHelper */

        try {
            if (count($configHelper->getConfiguration()->getConfigOption([])))
                throw new FileExistsException($configHelper->getConfiguration()->getConfigFile());
        } catch(FileException $ex) {
            throw new \RuntimeException('The global configuration is already created.', 0, $ex);
        }<commit_msg>Use a better way to detect if config file already exists in config:init<commit_after><?php

namespace vierbergenlars\CliCentral\Command\Config;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use vierbergenlars\CliCentral\Exception\Configuration\MissingConfigurationParameterException;
use vierbergenlars\CliCentral\Exception\File\FileException;
use vierbergenlars\CliCentral\Exception\File\FileExistsException;
use vierbergenlars\CliCentral\FsUtil;
use vierbergenlars\CliCentral\Helper\GlobalConfigurationHelper;

class InitCommand extends Command
{
    protected function configure()
    {
        $this->setName('config:init')
            ->addOption('no-create-missing', null, InputOption::VALUE_NONE, 'Do not create missing directories')
            ->setDescription('Initialize configuration')
            ->setHelp(<<<'EOF'
The <info>%command.name%</info> command presents a guide to do the initial configuration.
This command will ask interactive questions, unless <comment>--no-interaction|-n</comment> is used.

  <info>%command.full_name%</info>

It will help you to set up the configuration values <comment>applications-dir</comment>, <comment>vhosts-dir</comment>
and <comment>ssh-dir</comment>.

Non-existing directories will automatically be created, unless the <comment>--no-create-missing</comment> option is used.

This command can only be used to create the initial configuration file, it cannot be used to change configuration parameters.

To read configuration parameters, use the <info>config:get</info> command.
To set configuration parameters, use the <info>config:set</info> command.
To remove configuration parameters, use the <info>config:unset</info> command.
EOF
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $configHelper = $this->getHelper('configuration');
        /* @var $configHelper GlobalConfigurationHelper */

        try {
            if (file_exists($configHelper->getConfiguration()->getConfigFile()))
                throw new FileExistsException($configHelper->getConfiguration()->getConfigFile());
        } catch(FileException $ex) {
            throw new \RuntimeException('The global configuration is already created.', 0, $ex);
        }
{'fraction_non_alphanumeric': 0.10337213970293055, 'fraction_numerical': 0.0004014452027298274, 'mean_word_length': 4.51827242524917, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2118155', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1272, 'n_words': 346}