@param OutputInterface $output
@param string          $username

@return null|UserInterface|User
334719
protected function findUser(OutputInterface $output, string $username): ?User
    {
        try {
            /** @var User $user */

            return $this->userManager->loadUserByUsername($username);
        } catch (UsernameNotFoundException $e) {
            $message = $this->translator->trans(
                'user.does_not_exists',
                ['%username%' => $username],
                'security'
            );
            $output->writeln("<error>{$message}</error>");

            return null;
        }
    }
1239096
public function setOutput(\Parable\Http\Output\OutputInterface $output)
    {
        $this->output = $output;
        $this->output->init($this);
        return $this;
    }
151723
public function initConfig(OutputInterface $output = null)
    {
        $log = function ($message) use ($output) {
            if ($output) {
                $output->writeln($message);
            }
        };

        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            throw new \RuntimeException('This feature is currently only supported on Linux and OSX (maybe). Please submit a PR to support it on windows.');
        }

        $configDir = $this->getConfigDir();
        $distDir = $this->getDistConfigDir();

        if (!$this->filesystem->exists($configDir)) {
            $log('<info>[+] Creating directory:</info> '.$configDir);
            $this->filesystem->mkdir($configDir);
        }

        $configFilenames = [
            'alias.yml',
            'phpcrsh.yml',
        ];

        foreach ($configFilenames as $configFilename) {
            $srcFile = $distDir.'/'.$configFilename;
            $destFile = $configDir.'/'.$configFilename;

            if (!$this->filesystem->exists($srcFile)) {
                throw new \Exception('Dist (source) file "'.$srcFile.'" does not exist.');
            }

            if ($this->filesystem->exists($destFile)) {
                $log(sprintf('<info>File</info> %s <info> already exists, not overwriting.', $destFile));

                return;
            }

            $this->filesystem->copy($srcFile, $destFile);
            $log('<info>[+] Creating file:</info> '.$destFile);
        }
    }
1369937
public function getCredentials(OutputInterface $output)
    {
        $credentials = $this->parser->getCredentials();
        if ( is_null($credentials)) {
            $this->showErrorRunLlumInitFirst($output,"Credentials");
        };
        return $credentials;
    }
48173
protected function tryConnection($connectionInfo, OutputInterface $output)
    {
        if (\is_null($connectionInfo["dbName"])) {
            return false;
        }

        $dsn = "mysql:host=%s;port=%s";

        try {
            $connection = new \PDO(
                sprintf($dsn, $connectionInfo["host"], $connectionInfo["port"]),
                $connectionInfo["username"],
                $connectionInfo["password"]
            );
            $connection->query('SET NAMES \'UTF8\'');
        } catch (\PDOException $e) {
            $output->writeln(array(
                "<error>Wrong connection information</error>"
            ));

            return false;
        }

        return $connection;
    }
665599
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $userService = new UserService($this->userStore);

        /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
        $dialog = $this->getHelperSet()->get('dialog');

        // Function to validate mail address.
        $mailValidator = function ($answer) {
            if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                throw new \InvalidArgumentException(Lang::get('must_be_valid_email'));
            }

            return $answer;
        };

        $adminEmail = $dialog->askAndValidate($output, Lang::get('enter_email'), $mailValidator, false);
        $adminName = $dialog->ask($output, Lang::get('enter_name'));
        $adminPass = $dialog->askHiddenResponse($output, Lang::get('enter_password'));

        try {
            $userService->createUser($adminName, $adminEmail, $adminPass, true);
            $output->writeln(Lang::get('user_created'));
        } catch (\Exception $e) {
            $output->writeln(sprintf('<error>%s</error>', Lang::get('failed_to_create')));
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
        }
    }
1295577
protected function execute(InputInterface $input, OutputInterface $output): ?int
    {
        $username = $this->getUsername($input, $output);
        $user = $this->findUser($output, $username);
        if (null === $user) {
            return 1;
        }

        $user->setSuperAdmin(!$input->getOption('demote'));
        $this->userManager->save($user);

        if ($user->isSuperAdmin()) {
            $message = $this->translator->trans(
                'user.promoted',
                ['%username%' => $username],
                'security'
            );
        } else {
            $message = $this->translator->trans(
                'user.demoted',
                ['%username%' => $username],
                'security'
            );
        }
        $output->writeln("<info>{$message}</info>");

        return 0;
    }
370565
public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        $input  = $input ?: new ArgvInput();
        $output = $output ?: new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, null, $this->formatter());

        return parent::run($input, $output);
    }
1114576
public static function createDefaultLogger(OutputInterface $output) : LoggerInterface
    {
        $logger = new Logger('browscap');
        $consoleLogger = new ConsoleLogger($output);
        $psrHandler = new PsrHandler($consoleLogger);

        $logger->pushHandler($psrHandler);

        /** @var callable $memoryProcessor */
        $memoryProcessor = new MemoryUsageProcessor(true);
        $logger->pushProcessor($memoryProcessor);

        /** @var callable $peakMemoryProcessor */
        $peakMemoryProcessor = new MemoryPeakUsageProcessor(true);
        $logger->pushProcessor($peakMemoryProcessor);

        ErrorHandler::register($logger);

        return $logger;
    }
910022
protected function execute(InputInterface $input, OutputInterface $output): ?int
    {
        $username = $this->getUsername($input, $output);
        $user = $this->findUser($output, $username);
        if (null === $user) {
            return 1;
        }

        $password = $this->getPassword($input, $output);
        if ($password) {
            $this->userManager->setPlainTextPassword($user, $password);
        } else {
            $this->userManager->requestNewPassword($user);
        }
        $this->userManager->save($user);

        if ($password) {
            $message = $this->translator->trans(
                'user.password_changed_success',
                ['%username%' => $username],
                'security'
            );
        } else {
            $message = $this->translator->trans(
                'user.password_request_sent',
                ['%username%' => $username],
                'security'
            );
        }
        $output->writeln("<info>{$message}</info>");

        return 0;
    }
1076957
protected function gitHubUsername(InputInterface $input, OutputInterface $output)
    {
        $username = $input->getArgument('github_username');
        return isset($username) ? $username : $this->getGithubUserNameFromConfig($output);
    }
673309
protected function getTable(OutputInterface $output)
    {
        if (!\class_exists('Symfony\Component\Console\Helper\Table')) {
            return $this->getTableHelper();
        }

        $style = new TableStyle();
        $style
            ->setVerticalBorderChar(' ')
            ->setHorizontalBorderChar('')
            ->setCrossingChar('');

        $table = new Table($output);

        return $table
            ->setRows([])
            ->setStyle($style);
    }
946925
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
        $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
        $errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL);

        $context = json_decode($input->getOption('context') ?: '{}', true);
        $context['tenant_id'] = (string)$input->getOption('tenant-id');

        $nodeRef = NodeRef::fromString($input->getArgument('node-ref'));
        $consistent = $input->getOption('consistent') ? true : false;

        try {
            $node = $this->ncr->getNode($nodeRef, $consistent, $context);
            echo json_encode($node, $input->getOption('pretty') ? JSON_PRETTY_PRINT : 0) . PHP_EOL;
        } catch (\Throwable $e) {
            $errOutput->writeln($e->getMessage());
        }
    }
867054
protected function execute( InputInterface $input, OutputInterface $output ) {
		Log::instance()->setOutput( $output );

		$repository = RepositoryManager::instance()->setup( $input->getOption( 'repository' ) );

		if ( ! $repository ) {
			Log::instance()->write( 'Could not setup repository.', 0, 'error' );
			return 1;
		}

		$instances = $repository->getDB()->search( $input->getArgument( 'search_text' ) );

		if ( ! $instances ) {
			Log::instance()->write( 'An error occured while searching.', 0, 'success' );
		}

		if ( empty( $instances ) ) {
			Log::instance()->write( 'No snapshots found.', 0, 'warning' );
			return;
		}

		$table = new Table( $output );
		$table->setHeaders( [ 'ID', 'Project', 'Description', 'Author', 'Size', 'Multisite', 'Created' ] );

		$rows = [];

		foreach ( $instances as $instance ) {
			if ( empty( $instance['time'] ) ) {
				$instance['time'] = time();
			}

			$rows[ $instance['time'] ] = [
				'id'          => ( ! empty( $instance['id'] ) ) ? $instance['id'] : '',
				'project'     => ( ! empty( $instance['project'] ) ) ? $instance['project'] : '',
				'description' => ( ! empty( $instance['description'] ) ) ? $instance['description'] : '',
				'author'      => ( ! empty( $instance['author']['name'] ) ) ? $instance['author']['name'] : '',
				'size'        => ( ! empty( $instance['size'] ) ) ? Utils\format_bytes( (int) $instance['size'] ) : '',
				'multisite'   => ( ! empty( $instance['multisite'] ) ) ? 'Yes' : 'No',
				'created'     => ( ! empty( $instance['time'] ) ) ? date( 'F j, Y, g:i a', $instance['time'] ) : '',
			];
		}

		ksort( $rows );

		$table->setRows( $rows );

		$table->render();
	}
323992
protected function execute(InputInterface $input, OutputInterface $output)
	{
		$this->setupEnvironment('site', $input, $output);

		$version = new \JVersion;

		if ($input->getOption('short'))
		{
			$result = $version->getShortVersion();
		}
		elseif ($input->getOption('release'))
		{
			$result = $version->RELEASE;
		}
		else
		{
			$result = $version->getLongVersion();
		}
		$output->writeln($result);
	}
740715
protected function _outputHandle($output=null)
    {
        if ($output === null) {
            // do nothing
        } elseif ($output instanceof ResponseInterface) {
            $this->response = $output;
        } elseif ($output) {
            if (is_scalar($output)) {
                $this->response = $this->renderText($output);
            } elseif (is_array($output)) {
                $this->response = $this->renderJson($output);
            } elseif ($output instanceof Collection) {
                $this->response = $this->renderJson($output->all());
            }
        }
        
        if ($data = $this->getRenderBuffer()) {
            $this->response->write($data);
        }
        
        return $this->response;
    }
1240084
public function run(InputInterface $input = null, OutputInterface $output = null)
	{
		try
		{
			parent::run($input, $output);
		}
		catch (\Exception $e)
		{
			if (null === $output) {
				$output = new ConsoleOutput();
			}
			$message = array(
				$this->getLongVersion(),
				'',
				$e->getMessage(),
				''
			);
			$output->writeln($message);
		}
	}