<commit_before><?php
namespace CRM\CivixBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use CRM\CivixBundle\Builder\Collection;
use CRM\CivixBundle\Builder\Dirs;
use CRM\CivixBundle\Builder\Info;
use CRM\CivixBundle\Builder\License;
use CRM\CivixBundle\Builder\Module;
use CRM\CivixBundle\Utils\Path;

class InitCommand extends AbstractCommand
{
    protected function configure()
    {
        $this
            ->setName('generate:module')
            ->setDescription('Create a new CiviCRM Module-Extension')
            ->addArgument('<full.ext.name>', InputArgument::REQUIRED, 'Fully qualified extension name (e.g. "com.example.myextension")')
            //->addOption('type', null, InputOption::VALUE_OPTIONAL, 'Type of extension (e.g. "module", "payment", "report", "search")', 'module')
            ->addOption('license', null, InputOption::VALUE_OPTIONAL, 'License for the extension (' . implode(', ', $this->getLicenses()) .')', 'AGPL-3.0')
            ->addOption('author', null, InputOption::VALUE_REQUIRED, 'Name of the author', $this->getGitConfig('user.name'))
            ->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Email of the author', $this->getGitConfig('user.email'))
        ;
        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $licenses = new \LicenseData\Repository();

        $ctx = array();
        $ctx['type'] = 'module';
        $ctx['fullName'] = $input->getArgument('<full.ext.name>');
        $ctx['basedir'] = $ctx['fullName'];
        if (preg_match('/^[a-z0-9\.]+\.([a-z0-9]+)$/', $ctx['fullName'], $matches)) {
            $ctx['mainFile'] = $matches[1];
            $ctx['namespace'] = 'CRM/' . strtoupper($ctx['mainFile']{0}) . substr($ctx['mainFile'], 1);
        } else {
            $output->writeln('<error>Malformed package name</error>');
            return;
        }
        if ($input->getOption('author') && $input->getOption('email')) {
            $ctx['author'] = $input->getOption('author');
            $ctx['email'] = $input->getOption('email');
        } else {
            $output->writeln("<error>Missing author name or email address</error>");
            $output->writeln("<error>Please pass --author and --email, or set defaults in ~/.gitconfig</error>");
            return;
        }
        $ctx['license'] = $input->getOption('license');
        if (! $licenses->get($ctx['license'])) {
            $output->writeln('<error>Unrecognized license (' . $ctx['license'] . ')</error>');
            return;
        }
        $ext = new Collection();

        $output->writeln("<info>Initalize module ".$ctx['fullName']."</info>");
        $basedir = new Path($ctx['basedir']);
        $ext->builders['dirs'] = new Dirs(array(
            $basedir->string('build'),<commit_msg>CRM-13925 - generate:module - Display message about licensing/authorship<commit_after><?php
namespace CRM\CivixBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use CRM\CivixBundle\Builder\Collection;
use CRM\CivixBundle\Builder\Dirs;
use CRM\CivixBundle\Builder\Info;
use CRM\CivixBundle\Builder\License;
use CRM\CivixBundle\Builder\Module;
use CRM\CivixBundle\Utils\Path;

class InitCommand extends AbstractCommand
{
    protected function configure()
    {
        $this
            ->setName('generate:module')
            ->setDescription('Create a new CiviCRM Module-Extension')
            ->addArgument('<full.ext.name>', InputArgument::REQUIRED, 'Fully qualified extension name (e.g. "com.example.myextension")')
            //->addOption('type', null, InputOption::VALUE_OPTIONAL, 'Type of extension (e.g. "module", "payment", "report", "search")', 'module')
            ->addOption('license', null, InputOption::VALUE_OPTIONAL, 'License for the extension (' . implode(', ', $this->getLicenses()) .')', 'AGPL-3.0')
            ->addOption('author', null, InputOption::VALUE_REQUIRED, 'Name of the author', $this->getGitConfig('user.name'))
            ->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Email of the author', $this->getGitConfig('user.email'))
        ;
        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $licenses = new \LicenseData\Repository();

        $ctx = array();
        $ctx['type'] = 'module';
        $ctx['fullName'] = $input->getArgument('<full.ext.name>');
        $ctx['basedir'] = $ctx['fullName'];
        if (preg_match('/^[a-z0-9\.]+\.([a-z0-9]+)$/', $ctx['fullName'], $matches)) {
            $ctx['mainFile'] = $matches[1];
            $ctx['namespace'] = 'CRM/' . strtoupper($ctx['mainFile']{0}) . substr($ctx['mainFile'], 1);
        } else {
            $output->writeln('<error>Malformed package name</error>');
            return;
        }
        if ($input->getOption('author') && $input->getOption('email')) {
            $ctx['author'] = $input->getOption('author');
            $ctx['email'] = $input->getOption('email');
        } else {
            $output->writeln("<error>Missing author name or email address</error>");
            $output->writeln("<error>Please pass --author and --email, or set defaults in ~/.gitconfig</error>");
            return;
        }
        $ctx['license'] = $input->getOption('license');
        if ($licenses->get($ctx['license'])) {
            $output->writeln(sprintf('<comment>License set to %s (authored by %s \<%s>)</comment>', $ctx['license'], $ctx['author'], $ctx['email']));
            $output->writeln('<comment>If this is in error, please correct info.xml and LICENSE.txt</comment>');
        } else {
            $output->writeln('<error>Unrecognized license (' . $ctx['license'] . ')</error>');
            return;
        }
        $ext = new Collection();

        $output->writeln("<info>Initalize module ".$ctx['fullName']."</info>");
        $basedir = new Path($ctx['basedir']);
        $ext->builders['dirs'] = new Dirs(array(
            $basedir->string('build'),
{'fraction_non_alphanumeric': 0.18301158301158302, 'fraction_numerical': 0.003552123552123552, 'mean_word_length': 3.1780645161290324, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '6428897', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1889, 'n_words': 358}