Execute the command.

@param InputInterface $input
@param OutputInterface $output
@return null|int null or 0 if everything went fine, or an error code
@throws \Exception
972209
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $start = microtime(true);

        $this->setOutput($output);
        $this->setVerbosity($output->getVerbosity());

        $this->getContainer()->get('ez_migration_bundle.step_executed_listener.tracing')->setOutput($output);

        $migrationService = $this->getMigrationService();

        $migrationName = $input->getOption('migration');
        if ($migrationName != null) {
            $suspendedMigration = $migrationService->getMigration($migrationName);
            if (!$suspendedMigration) {
                throw new \Exception("Migration '$migrationName' not found");
            }
            if ($suspendedMigration->status != Migration::STATUS_SUSPENDED) {
                throw new \Exception("Migration '$migrationName' is not suspended, can not resume it");
            }

            $suspendedMigrations = array($suspendedMigration);
        } else {
            $suspendedMigrations = $migrationService->getMigrationsByStatus(Migration::STATUS_SUSPENDED);
        };

        $output->writeln('<info>Found ' . count($suspendedMigrations) . ' suspended migrations</info>');

        if (!count($suspendedMigrations)) {
            $output->writeln('Nothing to do');
            return 0;
        }

        // ask user for confirmation to make changes
        if ($input->isInteractive() && !$input->getOption('no-interaction')) {
            $dialog = $this->getHelperSet()->get('question');
            if (!$dialog->ask(
                $input,
                $output,
                new ConfirmationQuestion('<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>', false)
            )
            ) {
                $output->writeln('<error>Migration resuming cancelled!</error>');
                return 0;
            }
        }

        $executed = 0;
        $failed = 0;

        foreach($suspendedMigrations as $suspendedMigration) {
            $output->writeln("<info>Resuming {$suspendedMigration->name}</info>");

            try {
                $migrationService->resumeMigration($suspendedMigration, !$input->getOption('no-transactions'));

                $executed++;
            } catch (\Exception $e) {
                if ($input->getOption('ignore-failures')) {
                    $this->errOutput->writeln("\n<error>Migration failed! Reason: " . $e->getMessage() . "</error>\n");
                    $failed++;
                    continue;
                }
                $this->errOutput->writeln("\n<error>Migration aborted! Reason: " . $e->getMessage() . "</error>");
                return 1;
            }
        }

        $time = microtime(true) - $start;
        $output->writeln("Resumed $executed migrations, failed $failed");
        $output->writeln("Time taken: ".sprintf('%.2f', $time)." secs, memory: ".sprintf('%.2f', (memory_get_peak_usage(true) / 1000000)). ' MB');

        if ($failed) {
            return 2;
        }

        return 0;
    }
557886
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;

        if (null === ($backupDir = $input->getArgument('backup-dir'))) {
            $backupDir = $this->doAskBackupDir();
        }

        if (null === ($machine = $input->getOption('machine'))) {
            $machine = $this->doAskMachineName();
        }

        if (null === ($installDir = $input->getOption('install-dir'))) {
            $installDir = $this->doAskInstallDir();
        }

        $this->initDotfilesProfile($backupDir, $machine, $installDir);
    }
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);
		}
	}
608343
public function execute(InputInterface $input, OutputInterface $output)
    {
        if (empty($path = $input->getArgument('path'))) {
            $this->render($input, $output);
        } else {
            $this->test($input->getArgument('method'), $path, $input, $output);
        }

        return 0;
    }
623294
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        $outputFile = null;
        if ($file = $input->getOption('output-file')) {
            $outputFile = $file;
        }
        $this->service($input->getArgument($this->argument), $outputFile);
    }
1177449
protected function execute(InputInterface $input, OutputInterface $output)
  {
    $this->_input = $input;
    $this->_output = $output;

    $params = array_values($input->getArguments());
    //Strip off the command name
    array_shift($params);

    //Call the execute command with $input and $output as the first args
    if(method_exists($this, 'executeCommand'))
    {
      array_unshift($params, $input, $output);
      return $this->executeCommand(...$params);
    }

    //Call the process method, without $input and $output
    if(method_exists($this, 'process'))
    {
      return $this->process(...$params);
    }

    throw new \RuntimeException(
      "Your command must contain one of the following methods:\n" .
      "process()\n" .
      'executeCommand(InputInterface $input, OutputInterface $output)' . "\n",
      500
    );
  }
767927
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $path = $input->getOption('path');

        // if we're not given a path at all, try to figure it out
        if ($path === null) {
            $path = php_ini_loaded_file();
        }

        if (!is_file($path)) {
            throw new \Exception('Path is null or not accessible: "'.$path.'"');
        }
        $ini = parse_ini_file($path, true);

        $output->writeLn('Current PHP.ini settings from '.$path);
        $output->writeLn('##########');

        foreach ($ini as $section => $data) {
            $output->writeLn('<info>:: '.$section.'</info>');
            if (empty($data)) {
                $output->writeLn("\t<fg=yellow>No settings</fg=yellow>");
            } else {
                foreach ($data as $path => $value) {
                    $output->writeLn("\t".$path.' => '.var_export($value, true));
                }
            }
            $output->writeLn("-----------------\n");
        }

    }
174037
protected function execute(InputInterface $input, OutputInterface $output) : void
    {
        $io     = $this->getIO($input, $output);
        $config = $this->getConfig($input->getOption('configuration'), true);
        $repo   = new Repository();
        $args   = new Config\Options(['file' => $input->getOption('message')]);
        $name   = $input->getArgument('hook');
        $class  = '\\CaptainHook\\App\\Runner\\Hook\\' . Util::getHookCommand($name);

        /** @var \CaptainHook\App\Runner\Hook $hook */
        $hook = new $class($io, $config, $repo, $args);
        $hook->run();
    }
1161839
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $args = $this->prepareArgs($input->getArgument('exception'));
        $throwStmt = new Throw_(new StaticCall(new FullyQualifiedName(self::THROW_CLASS), 'fromThrowable', $args));
        $throwCode = $this->printer->prettyPrint([$throwStmt]);

        $shell = $this->getApplication();
        $shell->addCode($throwCode, !$shell->hasCode());
    }
919520
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $format = $input->getOption('format');
        $scan = new \Psecio\Iniscan\Scan();
        $rules = $scan->getRules();
        $options = array();

        $format = ($format === null) ? 'console' : $format;
        $formatClass = "\\Psecio\\Iniscan\\Command\\ListCommand\\Output\\".ucwords(strtolower($format));
        if (!class_exists($formatClass)) {
            throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "'.$format.'" not found');
        }
        $outputHandler = new $formatClass($output, $options);
        return $outputHandler->render($rules);
    }
513689
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $dryRun = $input->getOption('dry-run');
        $skipErrors = $input->getOption('skip-errors');
        $batchSize = NumberUtils::bound($input->getOption('batch-size'), 1, 1000);
        $batchDelay = NumberUtils::bound($input->getOption('batch-delay'), 100, 600000);
        $since = $input->getOption('since');
        $until = $input->getOption('until');
        $context = json_decode($input->getOption('context') ?: '{}', true);
        $context['tenant_id'] = (string)$input->getOption('tenant-id');
        $context['skip_errors'] = $skipErrors;
        $streamId = $input->getArgument('stream-id') ? StreamId::fromString($input->getArgument('stream-id')) : null;

        if (!empty($since)) {
            $since = Microtime::fromString(str_pad($since, 16, '0'));
        }

        if (!empty($until)) {
            $until = Microtime::fromString(str_pad($until, 16, '0'));
        }

        $io = new SymfonyStyle($input, $output);
        $io->title(sprintf('Replaying events from stream "%s"', $streamId ?? 'ALL'));
        $this->useInMemoryTransports($input, $io);
        if (!$this->readyForPbjxTraffic($io)) {
            return;
        }

        $this->createConsoleRequest();
        $pbjx = $this->getPbjx();
        $batch = 1;
        $i = 0;
        $replayed = 0;
        $io->comment(sprintf('Processing batch %d from stream "%s".', $batch, $streamId ?? 'ALL'));
        $io->comment(sprintf('context: %s', json_encode($context)));
        $io->newLine();

        $receiver = function (Event $event, StreamId $streamId) use (
            $output,
            $io,
            $pbjx,
            $dryRun,
            $skipErrors,
            $batchSize,
            $batchDelay,
            &$batch,
            &$replayed,
            &$i
        ) {
            ++$i;

            try {
                $output->writeln(
                    sprintf(
                        '<info>%d.</info> <comment>stream:</comment>%s, <comment>occurred_at:</comment>%s, ' .
                        '<comment>curie:</comment>%s, <comment>event_id:</comment>%s',
                        $i,
                        $streamId,
                        $event->get('occurred_at'),
                        $event::schema()->getCurie()->toString(),
                        $event->get('event_id')
                    )
                );

                if ($dryRun) {
                    $io->note(sprintf('DRY RUN - Would publish event "%s" here.', $event->get('event_id')));
                } else {
                    $event->isReplay(true);
                    $pbjx->publish($event);
                }

                ++$replayed;
            } catch (\Throwable $e) {
                $io->error(sprintf('%d. %s', $i, $e->getMessage()));
                $io->note(sprintf('%d. Failed event "%s" json below:', $i, $event->get('event_id')));
                $io->text(json_encode($event, JSON_PRETTY_PRINT));
                $io->newLine(2);

                if (!$skipErrors) {
                    throw $e;
                }
            }

            if (0 === $i % $batchSize) {
                ++$batch;

                if ($batchDelay > 0) {
                    $io->newLine();
                    $io->note(sprintf('Pausing for %d milliseconds.', $batchDelay));
                    usleep($batchDelay * 1000);
                }

                $io->comment(sprintf('Processing batch %d.', $batch));
                $io->newLine();
            }
        };

        if ($streamId) {
            $this->getPbjx()->getEventStore()->pipeEvents($streamId, $receiver, $since, $until, $context);
        } else {
            $this->getPbjx()->getEventStore()->pipeAllEvents($receiver, $since, $until, $context);
        }

        $io->newLine();
        $io->success(sprintf('Replayed %s events from stream "%s".', number_format($replayed), $streamId ?? 'ALL'));
    }
879140
protected function execute(InputInterface $input, OutputInterface $output)
    {
        try {
            $output->writeln([
                'File Creator',
                '=====================',
            ]);

            $filename = $input->getArgument('filename');
            $this->create($filename);

            $output->writeln('Create <bg=yellow;>'.$filename.'.md</> <options=bold>Success!!!</>');
            $output->writeln('');
        } catch (Exception $e) {
            $output->writeln('<bg=red;>'.$e->getMessage().'</> <options=bold></>');
            $output->writeln('');
        }
    }
496129
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $created = $this->scaffold(
            'ajax',
            [
                'CLASSNAME' => $input->getArgument('name'),
            ],
            [
                'ACTION' => $input->getOption('action'),
            ]
        );

        if ($created === true) {
            $output->writeln("<info>{$input->getArgument('name')} was created successfully</info>");
        } else {
            $output->writeln("<error>{$input->getArgument('name')} could not be created</error>");
        }
    }
983759
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->setIo($input, $output);

        $repo = $this->prepareRepository();

        $this->rebuild();

        $this->deployWithGit($repo);
    }
915365
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        $config = $this->parameters;
        $recursive = $input->getOption('recursive');
        $machine = $input->getOption('machine') ? $config->get('dotfiles.machine_name') : 'defaults';
        $backupDir = $config->get('dotfiles.backup_dir')."/src/$machine/home";
        $sourcePath = $input->getArgument('path');

        // detect source path
        $originPath = $this->detectPath($sourcePath);
        $relativePath = Toolkit::getRelativePath($originPath);
        if (0 === strpos($relativePath, '.')) {
            $relativePath = substr($relativePath, 1);
        }
        $relativePath = str_replace('.'.$sourcePath, $sourcePath, $relativePath);
        $targetPath = $backupDir.'/'.$relativePath;

        Toolkit::ensureDir($backupDir);

        $basename = basename($sourcePath);
        if (0 === strpos($basename, '.')) {
            $targetPath = str_replace('.'.$sourcePath, $basename, $targetPath);
        }

        if (is_dir($originPath)) {
            $this->doAddDir($originPath, $targetPath, $recursive);
        } else {
            $this->doAddFile($originPath, $targetPath);
        }
    }
451456
public function doRun(InputInterface $input, OutputInterface $output)
    {
        if (true === $input->hasParameterOption(array('--version', '-V'), true)) {
            $output->writeln($this->getLongVersion());

            return 0;
        }

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

        if (!$name) {
            $name = $this->defaultCommand;
            $input = new ArrayInput(array('command' => $this->defaultCommand));
        }

        try {
            $e = $this->runningCommand = null;
            // the command name MUST be the first element of the input
            $command = $this->find($name);
        } catch (\Exception $e) {
        } catch (\Throwable $e) {
        }
        if (null !== $e) {
            if (null !== $this->dispatcher) {
                $event = new ConsoleErrorEvent($input, $output, $e);
                $this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
                $e = $event->getError();

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

            throw $e;
        }

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

        return $exitCode;
    }
1225427
protected function execute(InputInterface $input, OutputInterface $output) : int
    {
        return !is_null($this->exitCode) ? $this->exitCode : 0;
    }