<commit_before><?php

namespace Bolt\Nut;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class UserAdd extends BaseCommand
{
    protected function configure()
    {
        $this
            ->setName('user:add')
            ->setDescription('Add a new user.')
            ->addArgument('username', InputArgument::REQUIRED, 'The username (loginname) you wish to add a role to.')
            ->addArgument('displayname', InputArgument::REQUIRED, 'The display name for the new user.')
            ->addArgument('email', InputArgument::REQUIRED, 'The email address for the new user.')
            ->addArgument('password', InputArgument::REQUIRED, 'The password for the new user.')
            ->addArgument('role', InputArgument::REQUIRED, 'The role you wish to give them.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $username = $input->getArgument('username');
        $password = $input->getArgument('password');
        $email = $input->getArgument('email');
        $displayname = $input->getArgument('displayname');
        $role = $input->getArgument('role');
        
        $user = $this->app['users']->getEmptyUser();
        $user['roles'] = array($role);
        $user['username'] = $username;
        $user['password'] = $password;
        $user['displayname'] = $displayname;
        $user['email'] = $email;
        
        $res = $this->app['users']->saveUser($user);
        if ($res) {
            $output->writeln("<info>Successfully created user: {$user['username']}</info>");
        } else {
            $output->writeln("<error>Error creating user: {$user['username']}</error>");
        }
    }
}<commit_msg>handle possible errors on availability<commit_after><?php

namespace Bolt\Nut;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class UserAdd extends BaseCommand
{
    protected function configure()
    {
        $this
            ->setName('user:add')
            ->setDescription('Add a new user.')
            ->addArgument('username', InputArgument::REQUIRED, 'The username (loginname) you wish to add a role to.')
            ->addArgument('displayname', InputArgument::REQUIRED, 'The display name for the new user.')
            ->addArgument('email', InputArgument::REQUIRED, 'The email address for the new user.')
            ->addArgument('password', InputArgument::REQUIRED, 'The password for the new <PASSWORD>.')
            ->addArgument('role', InputArgument::REQUIRED, 'The role you wish to give them.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $username = $input->getArgument('username');
        $password = $input->getArgument('password');
        $email = $input->getArgument('email');
        $displayname = $input->getArgument('displayname');
        $role = $input->getArgument('role');
        
        $user = $this->app['users']->getEmptyUser();
        $user['roles'] = array($role);
        $user['username'] = $username;
        $user['password'] = $password;
        $user['displayname'] = $displayname;
        $user['email'] = $email;
        
        $valid = true;
        if (! $app['users']->checkAvailability('username', $user['username'])) {
            $valid = false;
            $output->writeln("<error>Error creating user: username {$user['username']} already exists</error>");
        }
        if (! $app['users']->checkAvailability('email', $user['email'])) {
            $valid = false;
            $output->writeln("<error>Error creating user: email {$user['email']} exists</error>");
        }
        if (! $app['users']->checkAvailability('displayname', $user['displayname'])) {
            $valid = false;
            $output->writeln("<error>Error creating user: - display name {$user['displayname']} already exists</error>");
        }
        
        if ($valid) {
            $res = $this->app['users']->saveUser($user);
            if ($res) {
                $output->writeln("<info>Successfully created user: {$user['username']}</info>");
            } else {
                $output->writeln("<error>Error creating user: {$user['username']}</error>");
            }
        }
        
        
    }
}
{'fraction_non_alphanumeric': 0.16350924672981507, 'fraction_numerical': 0.0, 'mean_word_length': 2.7905982905982905, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 60, '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': '5741015', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1191, 'n_words': 264}