Start command.

@param OutputInterface $output      Output
@param bool            $longCommand Show long time message

@return Stopwatch
338236
protected static function startCommand(
        OutputInterface $output,
        $longCommand = false
    ): Stopwatch {
        self::configureFormatter($output);
        $stopwatch = new Stopwatch();
        $stopwatch->start('command');
        $output->writeln('');
        self::printSystemMessage(
            $output,
            self::getProjectHeader(),
            'Command started at '.date('r')
        );

        if ($longCommand) {
            self::printMessage(
                $output,
                self::getProjectHeader(),
                'This process may take a few minutes. Please, be patient'
            );
        }
        $output->writeln('');

        return $stopwatch;
    }
716149
public function runCommand($command, OutputInterface $output = null)
    {
        $input = new StringInput($command);

        $command = $this->find($this->getCommandName($input));

        return $command->run($input, $output ?: new NullOutput());
    }
582373
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $message = $input->getOption('message');
        $output->write("I HAVE A MESSAGE FOR YOU!");
        $wait = intval($input->getArgument('wait'));
        for ($counter = 0; $counter < $wait; $counter++) {
            $output->write(".");
            sleep(1);
        }
        $output->writeLn($message);
    }
361952
protected function writeLong(OutputInterface $output, array $result = null)
    {
        if ($result === null) {
            return;
        }

        $table = $this->getTable($output);

        foreach ($result as $label => $items) {
            $output->writeln('');
            $output->writeln(\sprintf('<strong>%s:</strong>', $label));

            $table->setRows([]);
            foreach ($items as $item) {
                $table->addRow([$this->formatItemName($item), $item['value']]);
            }

            if ($table instanceof TableHelper) {
                $table->render($output);
            } else {
                $table->render();
            }
        }
    }
1008190
public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        if (null === $input) {
            $input = $this->input;
        }

        if (null === $output) {
            $output = $this->output;
        }

        /* @codeCoverageIgnoreStart */
        if (
            !getenv('DOTFILES_BACKUP_DIR')
            && ('dev' !== getenv('DOTFILES_ENV'))
        ) {
            return $this->find('init')->run($input, $output);
        }
        /* @codeCoverageIgnoreEnd */
        $this->setDefaultCommand('shell');

        return parent::run($input, $output);
    }
869287
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->startCommand($output);
        $plugins = $this
            ->pluginRepository
            ->findAll();

        /**
         * @var Plugin $plugin
         */
        foreach ($plugins as $plugin) {
            $this->printMessage(
                $output,
                'Plugin',
                $plugin->getNamespace() . ' - [Hash : ' . $plugin->getHash() . ']'
            );
        }

        $this->finishCommand($output);
    }
1261486
protected function newProgressBar(OutputInterface $output)
    {
        // If the console output is not decorated (i.e. it does not support
        // ANSI), use NullOutput to suppress the progress bar entirely.
        $progressOutput = $output->isDecorated() ? $output : new NullOutput();

        return new ProgressBar($progressOutput);
    }
653255
protected function runCommand(InputInterface $input, OutputInterface $output)
    {
        $repository = $this->getRepository($input, $output);
        $file = $input->getArgument('file');

        self::exportToFile(
            $file,
            $output,
            function (Query $query) use ($repository) {
                return $repository->query($query);
            }
        );
    }
253011
protected function foreground(InputInterface $input, OutputInterface $output) {
		try {
			Daemon::run();
		} catch (\Exception $e) {
			$output->writeln('<error>' . $e->getMessage() . ': daemon not stopped</error>');
			return 1;
		}
	}
495302
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $logger = $this->getLogger();

        if (!$this->lock()) {
            $output->writeln('<comment>The command is already running in another process.</comment>');
            $logger->warning('Command is already running.');
        } else {
            try {
                $logger->info('Started export in command.');

                $orderVisitor = $this->getOrders();

                $this->getExporter()->exportOrders($orderVisitor, $this->getProgressBar($output, count($orderVisitor)));

                $logger->info('Finished export in command.');
            } catch (Exception $exc) {
                $logger->error('Stopped export in command.', ['exception' => $exc]);
            }
        }
    }
220411
private function startProcess(OutputInterface $output)
    {
        $arguments = $this->resolveProcessArgs();
        $name = sha1(serialize($arguments));
        if ($this->background->hasProcess($name)) {
            throw new \RuntimeException("Service is already running.");
        }

        $builder = new ProcessBuilder($arguments);

        if ($this->hasParameter('cwd')) {
            $builder->setWorkingDirectory($this->getParameter('cwd'));
        }

        $process = $builder->getProcess();

        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
            $output->writeln($process->getCommandLine());
        }

        if ($this->hasParameter('output')) {
            $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
            $stream = fopen($this->getParameter('output'), $append);
            $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
        }

        $process->start(
            function ($type, $buffer) use ($output) {
                $output->write($buffer);
            }
        );

        $this->background->addProcess($name, $process);

        if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
            throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
        }
    }
714524
public function runCommand($command, $parameters = array(), OutputInterface $output = null)
    {
        $parameters = array_merge(
            array('command' => $command),
            $this->getDefaultParameters(),
            $parameters
        );

        $this->getApplication()->setAutoExit(false);
        $exitCode = $this->getApplication()->run(new ArrayInput($parameters), $output ?: new NullOutput());

        if (1 === $exitCode) {
            throw new \RuntimeException('This command terminated with a permission error');
        }

        if (0 !== $exitCode) {
            $this->getApplication()->setAutoExit(true);

            $errorMessage = sprintf('The command terminated with an error code: %u.', $exitCode);
            $this->output->writeln("<error>$errorMessage</error>");
            $exception = new \Exception($errorMessage, $exitCode);

            throw $exception;
        }

        return $this;
    }
1040150
public function cli(InputInterface $input = null, OutputInterface $output = null)
  {
    $input = $input ?? new ArgvInput();
    $output = $output ?? new ConsoleOutput();

    $console = $this->getConsole();
    $this->_eventChannel->trigger(ConsolePrepareEvent::i($this->getContext(), $console, $input, $output));

    try
    {
      $exitCode = $console->run($input, $output);
    }
    catch(\Throwable $e)
    {
      $output->writeln("GENERIC EXCEPTION : " . $e->getCode());
      $output->writeln($e->getMessage());
      $exitCode = 1;
    }

    return $exitCode > 255 ? 255 : $exitCode;
  }
538142
protected function runCommand(InputInterface $input, OutputInterface $output)
    {
        list($appUUID, $indices) = $this->getRepositoryAndIndices($input, $output);
        $endpoints = $this->getEndpoints($input);

        $this
            ->repositoryBucket->findRepository($input->getArgument('app-name'))
            ->addToken(
                new Token(
                    TokenUUID::createById($input->getArgument('uuid')),
                    $appUUID,
                    $indices,
                    $endpoints,
                    $input->getOption('plugin'),
                    (int) $input->getOption('ttl')
                )
            );
    }
1175659
public function execute(InputInterface $input, string $start_state = null): OutputInterface
    {
        $execution_tracker = new ExecutionTracker($this);
        $next_state = $this->determineStartState($input, $start_state);
        do {
            $cur_cycle = $execution_tracker->track($next_state);
            $output = $next_state->execute($input);
            if ($next_state->isInteractive()) {
                break;
            }
            $next_state = $this->activateTransition($input, $output);
            $input = Input::fromOutput($output);
        } while ($next_state && $cur_cycle < self::MAX_CYCLES);

        if ($next_state && $cur_cycle === self::MAX_CYCLES) {
            throw CorruptExecutionFlow::fromExecutionTracker($execution_tracker, self::MAX_CYCLES);
        }
        return $output;
    }
1025320
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->startCommand($output);
        $plugins = $this
            ->pluginManager
            ->loadPlugins();

        foreach ($plugins as $plugin) {
            $this->printMessage(
                $output,
                'Plugin',
                'Plugin "' . $plugin->getNamespace() . '" installed'
            );
        }

        $this->finishCommand($output);
    }
914566
protected function runCommand(InputInterface $input, OutputInterface $output)
    {
        $repository = $this->getRepository($input, $output);
        $parameters = $input->getOption('parameter');
        self::makeQueryAndPrintResults(
            $input,
            $output,
            function (Query $query) use ($repository, $parameters) {
                return $repository->query($query, $parameters);
            }
        );
    }