Returns command.

@param InputInterface $input

@return CommandInterface
428517
protected function getCommand(InputInterface $input)
    {
        /** @var ServerRegistry $serverRegistry */
        $serverRegistry = $this->getContainer()->get('nanbando.server_registry');

        return $serverRegistry->getCommand($this->getServerName($input), $this->getName());
    }
465431
public function doRun(InputInterface $input, OutputInterface $output)
    {
        if (true === $input->hasParameterOption(['--version', '-V'], true)) {
            $output->writeln($this->getLongVersion());

            return 0;
        }

        try {
            // Makes ArgvInput::getFirstArgument() able to distinguish an option from an argument.
            $input->bind($this->getDefinition());
        } catch (ExceptionInterface $e) {
            // Errors must be ignored, full binding/validation happens later when the command is known.
        }

        $name = $this->getCommandName($input);
        if (true === $input->hasParameterOption(['--help', '-h'], true)) {
            if (!$name) {
                $name = 'help';
                $input = new ArrayInput(['command_name' => $this->defaultCommand]);
            } else {
                $this->wantHelps = true;
            }
        }

        if (!$name) {
            $name = $this->defaultCommand;
            $definition = $this->getDefinition();
            $definition->setArguments(array_merge(
                $definition->getArguments(),
                [
                    'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')->getDescription(), $name),
                ]
            ));
        }

        try {
            $this->runningCommand = null;
            // the command name MUST be the first element of the input
            $command = $this->find($name);
        } catch (\Throwable $e) {
            if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
                if (null !== $this->dispatcher) {
                    $event = new ConsoleErrorEvent($input, $output, $e);
                    $this->dispatcher->dispatch($event, ConsoleEvents::ERROR);

                    if (0 === $event->getExitCode()) {
                        return 0;
                    }

                    $e = $event->getError();
                }

                throw $e;
            }

            $alternative = $alternatives[0];

            $style = new SymfonyStyle($input, $output);
            $style->block(sprintf("\nCommand \"%s\" is not defined.\n", $name), null, 'error');
            if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
                if (null !== $this->dispatcher) {
                    $event = new ConsoleErrorEvent($input, $output, $e);
                    $this->dispatcher->dispatch($event, ConsoleEvents::ERROR);

                    return $event->getExitCode();
                }

                return 1;
            }

            $command = $this->find($alternative);
        }

        $this->runningCommand = $command;
        $exitCode = $this->doRunCommand($command, $input, $output);
        $this->runningCommand = null;

        return $exitCode;
    }
326693
final public function console(InputInterface $input)
    {
        if (!$input) {
            $input = new ArgvInput();
        }
        $application = new Application($this);
        return $application->run($input);
    }
227191
private function generateOutput(InputInterface $input): OutputInterface
    {
        return new Output(
            $this->name,
            array_merge(
                $this->evaluateInputExports($input),
                $this->generateOutputParams($input)
            )
        );
    }
761302
public function execute(InputInterface $input, OutputInterface $output)
    {
        $runner = $this->commandDefinition->getRunner();
        $runner();
    }
594086
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;

        try {
            return $this->fire();
        } catch (DomainException $e) {
            return 1;
        } catch (Exception $e) {
            $this->error($e->getMessage());
            $this->error('Abort!');
        }

        return;
    }
218661
public function execute(InputInterface $input): OutputInterface
    {
        $this->validator->validateInput($this, $input);
        $output = $this->generateOutput($input);
        $this->validator->validateOutput($this, $output);
        return $output;
    }
1207558
public function getArgument(InputInterface $input, $key)
    {
        if ($input->hasArgument($key)) {
            return $input->getArgument($key);
        }

        if (isset($this->arguments[$key])) {
            return $this->arguments[$key];
        }

        return false;
    }
1041112
protected function getSites(InputInterface $input)
    {
        $parameters = [];
        $identifiers = $input->getOption('site');

        if ('all' !== current($identifiers)) {
            $parameters['id'] = 1 === \count($identifiers) ? current($identifiers) : $identifiers;
        }

        return $this->getSiteManager()->findBy($parameters);
    }
323058
public function handle(CommandInterface $command)
    {
        $handleAll = $command->getParameter('selectedAll');
        $ids = $command->getParameter('selected');

        try {
            $this->queryExecutor->beginTransaction();

            if ($handleAll) {
                $criteria = \json_decode($command->getParameter('query'), true);
                $this->displayCriteriaFactory->setAttributes($criteria);
                $displayCriteria = $this->displayCriteriaFactory->createCriteria([
                    'filter' => $this->filterFactory->create($criteria['filter_type']),
                ]);
                $displayCriteria->getPager()->disable();

                $this->handleAll($displayCriteria);
            } else {
                foreach ($ids as $id) {
                    $result = $this->handleOne($id);

                    if (!$result->isSuccessful()) {
                        throw new \Exception();
                    }
                }
            }

            $this->queryExecutor->commit();
        } catch (\Exception $e) {
            $this->queryExecutor->rollback();

            $return = CommandResult::error('batch_error');
            if (isset($result)) {
                $return->addMessages($result->getMessages());
            }

            return $return;
        }

        return CommandResult::success('batch_success', ['%count%' => \count($ids)]);
    }
522501
protected function findCommand(IInput $input, IConsole $console) {
        if ($input->hasArgument('command')) {
            $matcher = new ArgumentsMatcher(new ArgumentsParser());

            return $matcher->findCommand(
                $console->getCommands(), $input->getArgument('command')
            );
        }

        return $input->getCommand();
    }
819208
protected function setup(InputInterface $input)
    {
        return $this->setup
            ->setForcedRollback($input->getOption('force-rollback'))
            ->setExecuteQueries($input->getOption('execute'))
            ->setRollbackedFirst($input->getOption('rollback-first'))
            ->run();
    }
153146
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $method = method_exists($this, 'process') ? 'process' : 'handle';

        return $this->{$method}();
    }
805755
protected function interact(InputInterface $input, OutputInterface $output)
    {
        if (!$input->getArgument('username')) {
            $question = new Question('Please choose a username:');
            $question->setValidator(function ($username) {
                if (null === $username) {
                    throw new \InvalidArgumentException('Username can not be empty');
                }

                return $username;
            });
            $username = $this->getHelper('question')->ask(
                $input,
                $output,
                $question
            );
            $input->setArgument('username', $username);
        }

        if (!$input->getArgument('email')) {
            $question = new Question('Please choose an email:');
            $question->setValidator(function ($email) {
                if (null === $email) {
                    throw new \InvalidArgumentException('Email can not be empty');
                }

                return $email;
            });
            $email = $this->getHelper('question')->ask(
                $input,
                $output,
                $question
            );
            $input->setArgument('email', $email);
        }

        if (!$input->getArgument('password')) {
            $question = new Question('Please choose a password:');
            $question->setHidden(true);
            $question->setHiddenFallback(false);
            $question->setValidator(function ($password) {
                if (null === $password) {
                    throw new \InvalidArgumentException('Password can not be empty');
                }

                return $password;
            });
            $password = $this->getHelper('question')->ask(
                $input,
                $output,
                $question
            );

            $input->setArgument('password', $password);
        }

        if (!$input->getArgument('locale')) {
            $locale = $this->getHelper('question')->ask(
                $input,
                $output,
                new Question('Please enter the locale (or leave empty for default admin locale):')
            );
            $input->setArgument('locale', $locale);
        }

        if (!$input->getOption('group')) {
            $question = new ChoiceQuestion(
                'Please enter the group(s) the user should be a member of (multiple possible, separated by comma):',
                $this->groups,
                ''
            );
            $question->setMultiselect(true);
            $question->setValidator(function ($groupsInput) {
                if (!$this->groups) {
                    throw new \RuntimeException('No user group(s) could be found');
                }

                // Validate that the chosen group options exist in the available groups
                $groupNames = array_unique(explode(',', $groupsInput));
                if (count(array_intersect_key(array_flip($groupNames), $this->groups)) !== count($groupNames)) {
                    throw new InvalidArgumentException('You have chosen non existing group(s)');
                }

                if ($groupsInput === '') {
                    throw new \RuntimeException(
                        'Group(s) must be of type integer and can not be empty'
                    );
                }

                return $groupsInput;
            });

            // Group has to be imploded because $input->setOption expects a string
            $groups = $this->getHelper('question')->ask($input, $output, $question);

            $input->setOption('group', $groups);
        }
    }
364517
public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        if (null === $input) {
            // rewrite the input for single command usage
            $argv = $_SERVER['argv'];
            $scriptName = array_shift($argv);
            array_unshift($argv, 'lint');
            array_unshift($argv, $scriptName);
            $input = new ArgvInput($argv);
        }

        return parent::run($input, $output);
    }
377705
protected function getOptions(InputInterface $input)
    {
        $opts = array();

        foreach ($this->sshOptionOptions as $key => $option) {
            if ($input->getOption($key)) {
                $opts[$option] = $input->getOption($key);
            }
        }

        if ($input->getOption('keyfile')) {
            $opts['PasswordAuthentication'] = 'no';
            $opts['PubkeyAuthentication'] = 'yes';
            $opts['IdentitiesOnly'] = 'yes';
            $opts['IdentityFile'] = $input->getOption('keyfile');
        } else if ($input->getOption('password')) {
            $opts['PasswordAuthentication'] = 'yes';
            $opts['PubkeyAuthentication'] = 'no';
        }

        return $opts;
    }
122566
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $command = sprintf(
            'exec -i %s %s',
            $input->getArgument('container'),
            $input->getArgument('execcmd')
        );

        $response = $this->getFacade()->runDocker($command);

        if ($output->isVerbose()) {
            $output->writeln($response);
        }
    }