/** * Executes the application. * * Available options: * * * interactive: Sets the input interactive flag * * decorated: Sets the output decorated flag * * verbosity: Sets the output verbosity flag * * capture_stderr_separately: Make output of stdOut and stdErr separately available * * @param array $input An array of arguments and options * @param array $options An array of options * * @return int The command exit code */ public function run(array $input, $options = array()) { $this->input = new ArrayInput($input); if (isset($options['interactive'])) { $this->input->setInteractive($options['interactive']); } $this->captureStreamsIndependently = array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately']; if (!$this->captureStreamsIndependently) { $this->output = new StreamOutput(fopen('php://memory', 'w', false)); if (isset($options['decorated'])) { $this->output->setDecorated($options['decorated']); } if (isset($options['verbosity'])) { $this->output->setVerbosity($options['verbosity']); } } else { $this->output = new ConsoleOutput(isset($options['verbosity']) ? $options['verbosity'] : ConsoleOutput::VERBOSITY_NORMAL, isset($options['decorated']) ? $options['decorated'] : null); $errorOutput = new StreamOutput(fopen('php://memory', 'w', false)); $errorOutput->setFormatter($this->output->getFormatter()); $errorOutput->setVerbosity($this->output->getVerbosity()); $errorOutput->setDecorated($this->output->isDecorated()); $reflectedOutput = new \ReflectionObject($this->output); $strErrProperty = $reflectedOutput->getProperty('stderr'); $strErrProperty->setAccessible(true); $strErrProperty->setValue($this->output, $errorOutput); $reflectedParent = $reflectedOutput->getParentClass(); $streamProperty = $reflectedParent->getProperty('stream'); $streamProperty->setAccessible(true); $streamProperty->setValue($this->output, fopen('php://memory', 'w', false)); } return $this->statusCode = $this->application->run($this->input, $this->output); }
/** * Runs the current application. * * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code */ public function doRun(InputInterface $input, OutputInterface $output) { $output->writeLn($this->getHeader()); $name = $this->getCommandName($input); if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->run(); return 0; } if (true === $input->hasParameterOption(array('--ansi'))) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-ansi'))) { $output->setDecorated(false); } if (true === $input->hasParameterOption(array('--help', '-h'))) { if (!$name) { $name = 'help'; $input = new ArrayInput(array('command' => 'help')); } else { $this->wantHelps = true; } } if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); } if (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) { $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); if (!posix_isatty($inputStream)) { $input->setInteractive(false); } } if (true === $input->hasParameterOption(array('--quiet', '-q'))) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } if (true === $input->hasParameterOption(array('--version', '-V'))) { $output->writeln($this->getLongVersion()); return 0; } if (!$name) { $name = 'list'; $input = new ArrayInput(array('command' => 'list')); } // the command name MUST be the first element of the input $command = $this->find($name); $this->runningCommand = $command; $statusCode = $command->run($input, $output); $this->runningCommand = null; # write Footer $output->writeLn($this->getFooter()); return is_numeric($statusCode) ? $statusCode : 0; }
protected function setupOutput() { $outputResource = $this->getLogsResource(); $this->output = new StreamOutput($outputResource); $this->output->setDecorated(false); $this->output->setVerbosity(true); }
protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); $binDir = $composer->getConfig()->get('bin-dir'); if ($input->getOption('list') || !$input->getArgument('binary')) { $bins = glob($binDir . '/*'); if (!$bins) { throw new \RuntimeException("No binaries found in bin-dir ({$binDir})"); } $this->getIO()->write(<<<EOT <comment>Available binaries:</comment> EOT ); foreach ($bins as $bin) { // skip .bat copies if (isset($previousBin) && $bin === $previousBin . '.bat') { continue; } $previousBin = $bin; $bin = basename($bin); $this->getIO()->write(<<<EOT <info>- {$bin}</info> EOT ); } return; } $binary = $input->getArgument('binary'); $dispatcher = $composer->getEventDispatcher(); $dispatcher->addListener('__exec_command', $binary); if ($output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } return $dispatcher->dispatchScript('__exec_command', true, $input->getArgument('args')); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return integer */ protected function execute(InputInterface $input, OutputInterface $output) { $this->typeCheck->execute(func_get_args()); $this->isolator->chdir($input->getArgument('path')); $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $configuration = $this->getApplication()->configurationReader()->read(null, true); $this->includeLoaders($configuration, $output); $output->writeln('<info>Checking for correct Typhoon setup...</info>'); $result = $this->analyzer()->analyze($configuration); if (count($result->issues()) < 1) { $output->writeln('<info>No problems detected.</info>'); } else { if (count($result->issuesBySeverity(IssueSeverity::ERROR())) > 0) { $output->writeln(''); $output->writeln($this->generateErrorBlock($result)); } if (count($result->issuesBySeverity(IssueSeverity::WARNING())) > 0) { $output->writeln(''); $output->writeln($this->generateWarningBlock($result)); } } if ($result->isError()) { return 1; } return 0; }
/** * @param OutputInterface $output * @return OutputLogger */ protected function getLogger(OutputInterface $output) { if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } return new OutputLogger($output); }
/** * {@inheritdoc} * * @see PlatformCommand::getCurrentEnvironment() */ protected function execute(InputInterface $input, OutputInterface $output) { /** @var \Symfony\Component\Console\Helper\ProcessHelper $process */ $process = $this->getHelper('process'); $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); if (!is_dir(Platform::rootDir() . '/docker/fg')) { $process->mustRun($output, ['git', 'clone', 'https://github.com/brendangregg/FlameGraph.git', Platform::rootDir() . '/docker/fg']); } if (!is_dir(Platform::rootDir() . '/docker/xhpfg')) { $process->mustRun($output, ['git', 'clone', 'https://github.com/msonnabaum/xhprof-flamegraphs.git', Platform::rootDir() . '/docker/xhpfg']); } $stack = StacksFactory::getStack(Platform::webDir()); switch ($stack->type()) { case Stacks\Drupal::TYPE: $this->stdOut->writeln("<comment>Patching Drupal for xhprof</comment>"); $patchProcess = new Process('patch -p1 < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir()); break; case Stacks\WordPress::TYPE: $this->stdOut->writeln("<comment>Patching WordPress for xhprof</comment>"); $patchProcess = new Process('patch -p0 < ' . CLI_ROOT . '/resources/wordpress-enable-profiling.patch', Platform::webDir()); break; default: throw new \Exception('Stack type not supported yet.'); } $patchProcess->mustRun(); }
/** * Configure output stream parameters. * * @param OutputInterface $output */ protected function configureOutputStream(OutputInterface $output) { $verbosity = $this->getOutputVerbosity() ? OutputInterface::VERBOSITY_VERBOSE : OutputInterface::VERBOSITY_NORMAL; $output->setVerbosity($verbosity); if (null !== $this->isOutputDecorated()) { $output->getFormatter()->setDecorated($this->isOutputDecorated()); } }
protected function doCommand(OutputInterface $output, $verbosity, $command, $args) { $oldVerbosity = $output->getVerbosity(); $output->setVerbosity($verbosity); $c = $this->getApplication()->find($command); $input = new \Symfony\Component\Console\Input\ArrayInput(array_merge(array('command' => $c), $args)); $c->run($input, $output); $output->setVerbosity($oldVerbosity); }
public function doRun(InputInterface $input, OutputInterface $output) { // introspect input without definition $config = $input->getParameterOption(array('--config', '-c')); $verbose = $input->getParameterOption(array('--verbose', '-v')); $bootstrap = $input->getParameterOption(array('--bootstrap', '-b')); $profile = $input->getParameterOption(array('--profile', '-p')); if (true == $verbose) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } $container = $this->getContainer(); // event dispatcher $container['dispatcher'] = new EventDispatcher(); $container['input'] = $input; $container['output'] = $output; // config /** * Process options */ $this->register(new ConfigServiceProvider(), array('config.path' => $config)); if ($profile) { $container['config.profile'] = $profile; } $overrides = array(); if ($input->hasParameterOption(array('--verbose', '-v'))) { $overrides['verbose'] = true; } if ($bootstrap) { $overrides['bootstrap'] = $bootstrap; } $container['config.overrides'] = $overrides; /** * Should overwrite the profile with command line options here */ $profile = $container['profile']; if ($profile->bootstrap) { $inc = function () use($profile) { require $profile->bootstrap; }; $inc(); } // extensions foreach ($profile->extensions as $name => $options) { $class = "\\DSpec\\Provider\\" . ucfirst($name) . "ServiceProvider"; if (!class_exists($class)) { $class = $name; if (!class_exists($class)) { throw new \InvalidArgumentException("class:{$class} not found"); } } $this->register(new $class(), (array) $options); } $container['dspec.command'] = new DSpecCommand($container); $this->bootProviders(); $this->add($container['dspec.command']); return parent::doRun($input, $output); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->isVerbose = OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity(); if (!$this->isVerbose && $this->config->verboseMode) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $this->isVerbose = true; } $this->output = $output; }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $this->typeCheck->execute(func_get_args()); $this->isolator->chdir($input->getArgument('path')); $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $configuration = $this->getApplication()->configurationReader()->read(null, true); $this->includeLoaders($configuration, $output); $output->writeln('<info>Generating classes...</info>'); $this->generator()->generate($configuration); $output->writeln('<info>Done.</info>'); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!empty($input->getOption('debug')) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } $output->writeln($this->getApplication()->getLongVersion() . "\n", Output::VERBOSITY_VERBOSE); $formatter = KeyLighter::get()->getFormatter($input->getOption('format')) ?: KeyLighter::get()->getDefaultFormatter(); foreach ($input->getArgument('path') as $filename) { $this->process($input, $output, $filename, $formatter); } }
public function execute(InputInterface $input, OutputInterface $output) { $output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString()); $options = $input->getOptions(); if ($options['debug']) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } $options['verbosity'] = $output->getVerbosity(); if (!extension_loaded('curl')) { throw new \Exception("Codeception requires CURL extension installed to make tests run\n" . "If you are not sure, how to install CURL, pls refer to StackOverflow\n\n" . "Notice: PHP for Apache/Nginx and CLI can have different php.ini files.\n" . "Please make sure that your PHP you run from console has CURL enabled."); } $config = Configuration::config($options['config']); $suite = $input->getArgument('suite'); $test = $input->getArgument('test'); if (!Configuration::isEmpty() && !$test && strpos($suite, $config['paths']['tests']) === 0) { list($matches, $suite, $test) = $this->matchTestFromFilename($suite, $config['paths']['tests']); } if ($options['group']) { $output->writeln(sprintf("[Groups] <info>%s</info> ", implode(', ', $options['group']))); } if ($input->getArgument('test')) { $options['steps'] = true; } if ($test) { $filter = $this->matchFilteredTestName($test); $options['filter'] = $filter; } $this->codecept = new \Codeception\Codecept((array) $options); if ($suite and $test) { $this->codecept->run($suite, $test); } if (!$test) { $suites = $suite ? explode(',', $suite) : Configuration::suites(); $current_dir = Configuration::projectDir(); $executed = $this->runSuites($suites, $options['skip']); foreach ($config['include'] as $included_config_file) { Configuration::config($full_path = $current_dir . $included_config_file); $namespace = $this->currentNamespace(); $output->writeln("\n<fg=white;bg=magenta>\n[{$namespace}]: tests from {$full_path}\n</fg=white;bg=magenta>"); $suites = $suite ? explode(',', $suite) : Configuration::suites(); $executed += $this->runSuites($suites, $options['skip']); } if (!$executed) { throw new \RuntimeException(sprintf("Suite '%s' could not be found", implode(', ', $suites))); } } $this->codecept->printResult(); if (!$input->getOption('no-exit')) { if ($this->codecept->getResult()->failureCount() or $this->codecept->getResult()->errorCount()) { exit(1); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ public function loadCommands(InputInterface $input, OutputInterface $output) { // $application is required to be defined in the register_command scripts $application = $this->application; $inputDefinition = $application->getDefinition(); $inputDefinition->addOption(new InputOption('no-warnings', null, InputOption::VALUE_NONE, 'Skip global warnings, show command output only', null)); try { $input->bind($inputDefinition); } catch (\RuntimeException $e) { //expected if there are extra options } if ($input->getOption('no-warnings')) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } require_once __DIR__ . '/../../../core/register_command.php'; if ($this->config->getSystemValue('installed', false)) { if (\OCP\Util::needUpgrade()) { $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available"); $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); } elseif ($this->config->getSystemValue('maintenance', false)) { $output->writeln("ownCloud is in maintenance mode - no app have been loaded"); } else { OC_App::loadApps(); foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { $appPath = \OC_App::getAppPath($app); if ($appPath === false) { continue; } \OC::$loader->addValidRoot($appPath); $file = $appPath . '/appinfo/register_command.php'; if (file_exists($file)) { require $file; } } } } else { $output->writeln("ownCloud is not installed - only a limited number of commands are available"); } $input = new ArgvInput(); if ($input->getFirstArgument() !== 'check') { $errors = \OC_Util::checkServer(\OC::$server->getConfig()); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln((string) $error['error']); $output->writeln((string) $error['hint']); $output->writeln(''); } throw new \Exception("Environment not properly prepared."); } } }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } /** @var ChannelRepository $repository */ /** @var SyncProcessor $processor */ $connector = $input->getOption('connector'); $integrationId = $input->getOption('integration-id'); $batchSize = $input->getOption('transport-batch-size'); $connectorParameters = $this->getConnectorParameters($input); $entityManager = $this->getService('doctrine.orm.entity_manager'); $repository = $entityManager->getRepository('OroIntegrationBundle:Channel'); $logger = new OutputLogger($output); $entityManager->getConnection()->getConfiguration()->setSQLLogger(null); $exitCode = self::STATUS_SUCCESS; if ($this->isJobRunning($integrationId)) { $logger->warning('Job already running. Terminating....'); return self::STATUS_SUCCESS; } if ($integrationId) { $integration = $repository->getOrLoadById($integrationId); if (!$integration) { $logger->critical(sprintf('Integration with given ID "%d" not found', $integrationId)); return self::STATUS_FAILED; } $integrations = [$integration]; } else { $integrations = $repository->getConfiguredChannelsForSync(null, true); } /* @var Integration $integration */ foreach ($integrations as $integration) { try { $logger->notice(sprintf('Run sync for "%s" integration.', $integration->getName())); $this->updateToken($integration); if ($batchSize) { $integration->getTransport()->getSettingsBag()->set('page_size', $batchSize); } $processor = $this->getSyncProcessor($integration, $logger); $result = $processor->process($integration, $connector, $connectorParameters); $exitCode = $result ?: self::STATUS_FAILED; } catch (\Exception $e) { $logger->critical($e->getMessage(), ['exception' => $e]); $exitCode = self::STATUS_FAILED; continue; } } $logger->notice('Completed'); return $exitCode; }
/** * Initialises the command just after the input has been validated. * * This is mainly useful when a lot of commands extends one main command * where some things need to be initialised based on the input arguments and options. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * @return void */ protected function initialize(InputInterface $input, OutputInterface $output) { $this->parseConfig($input->getOptions(), $this->getNativeDefinition()->getOptionDefaults()); $config = $this->getConfig(); // Configure Redis Resque\Redis::setConfig(array('scheme' => $config['scheme'], 'host' => $config['host'], 'port' => $config['port'], 'namespace' => $config['namespace'], 'password' => $config['password'])); // Set the verbosity if (array_key_exists('verbose', $config)) { if (!$input->getOption('verbose') and !$input->getOption('quiet') and is_int($config['verbose'])) { $output->setVerbosity($config['verbose']); } else { $this->config['verbose'] = $output->getVerbosity(); } } // Set the monolog loggers, it's possible to speficfy multiple handlers $logs = array_key_exists('log', $config) ? array_unique($config['log']) : array(); empty($logs) and $logs[] = 'console'; $handlerConnector = new Resque\Logger\Handler\Connector($this, $input, $output); $handlers = array(); foreach ($logs as $log) { $handlers[] = $handlerConnector->resolve($log); } $this->logger = $logger = new Resque\Logger($handlers); // Unset some variables so as not to pass to include file unset($logs, $handlerConnector, $handlers); // Include file? if (array_key_exists('include', $config) and strlen($include = $config['include'])) { if (!($includeFile = realpath(dirname($include) . '/' . basename($include))) or !is_readable($includeFile) or !is_file($includeFile) or substr($includeFile, -4) !== '.php') { throw new \InvalidArgumentException('The include file "' . $include . '" is not a readable php file.'); } try { require_once $includeFile; } catch (\Exception $e) { throw new \RuntimeException('The include file "' . $include . '" threw an exception: "' . $e->getMessage() . '" on line ' . $e->getLine()); } } // This outputs all the events that are fired, useful for learning // about when events are fired in the command flow if (array_key_exists('events', $config) and $config['events'] === true) { Resque\Event::listen('*', function ($event) use($output) { $data = array_map(function ($d) { $d instanceof \Exception and $d = '"' . $d->getMessage() . '"'; is_array($d) and $d = '[' . implode(',', $d) . ']'; return (string) $d; }, array_slice(func_get_args(), 1)); $output->writeln('<comment>-> event:' . Resque\Event::eventName($event) . '(' . implode(',', $data) . ')</comment>'); }); } }
/** * {@inheritdoc} * * @see PlatformCommand::getCurrentEnvironment() */ protected function execute(InputInterface $input, OutputInterface $output) { /** @var \Symfony\Component\Console\Helper\ProcessHelper $process */ $process = $this->getHelper('process'); $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); if (!is_dir(Platform::rootDir() . '/docker/fg')) { $process->mustRun($output, ['git', 'clone', 'https://github.com/brendangregg/FlameGraph.git', Platform::rootDir() . '/docker/fg']); } if (!is_dir(Platform::rootDir() . '/docker/xhpfg')) { $process->mustRun($output, ['git', 'clone', 'https://github.com/msonnabaum/xhprof-flamegraphs.git', Platform::rootDir() . '/docker/xhpfg']); } $this->stdOut->writeln("<comment>Patching Drupal for xhprof</comment>"); $patchProcess = new Process('patch -p1 < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir()); $patchProcess->mustRun(); }
/** * {@inheritdoc} */ protected function initialize(InputInterface $input, OutputInterface $output) { if ($input->hasOption('no-output') && true === $input->getOption('no-output')) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } if ($input->hasOption('dump')) { $this->dumpMode = $input->getOption('dump'); } $this->logPath = $this->getContainer()->getParameter('jmose_command_scheduler.log_path'); // If logpath is not set to false, append the directory separator to it if (false !== $this->logPath) { $this->logPath = rtrim($this->logPath, '/\\') . DIRECTORY_SEPARATOR; } // store the original verbosity before apply the quiet parameter $this->commandsVerbosity = $output->getVerbosity(); if ($input->hasOption('no-output') && true === $input->getOption('no-output')) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } // all configuration to input and output done, save references $this->input = $input; $this->output = $output; // get doctrine manager $this->entityManager = $this->getContainer()->get('doctrine')->getManager($this->getContainer()->getParameter('jmose_command_scheduler.doctrine_manager')); }
/** * {@inheritdoc} * * @see PlatformCommand::getCurrentEnvironment() */ protected function execute(InputInterface $input, OutputInterface $output) { /** @var ShellHelper $shell */ $shell = $this->getHelper('shell'); $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); $shell->setOutput($output); if (!is_dir(LocalProject::getProjectRoot() . '/docker/fg')) { $shell->execute(['git', 'clone', 'https://github.com/brendangregg/FlameGraph.git', LocalProject::getProjectRoot() . '/docker/fg']); } if (!is_dir(LocalProject::getProjectRoot() . '/docker/xhpfg')) { $shell->execute(['git', 'clone', 'https://github.com/msonnabaum/xhprof-flamegraphs.git', LocalProject::getProjectRoot() . '/docker/xhpfg']); } $this->stdOut->writeln("<comment>Patching Drupal for xhprof</comment>"); $process = new Process('patch -p1 < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir()); $process->mustRun(null); }
protected function execute(InputInterface $input, OutputInterface $output) { $reset = !$input->getOption('no-reset'); $index = $input->getOption('index'); $type = $input->getOption('type'); $maxTimeExecution = (int) $input->getOption('timeout'); /*if (null === $index && null !== $type) { throw new \InvalidArgumentException('Cannot specify type option without an index.'); }*/ if (null === $index) { throw new \InvalidArgumentException('You must specify an index.'); } $options['slice'] = $input->getOption('batch'); $clearCache = !$input->getOption('no-clear-cache'); //cache needs to be refreshed if ($clearCache) { $kernel = $this->getContainer()->get('kernel'); //cache:clear command is called $command = new CacheClearCommand(); $command->setContainer($this->getContainer()); $ccInput = new ArrayInput(array()); $command->run($ccInput, new NullOutput()); $args = array_merge(array('php', $kernel->getRootDir() . DIRECTORY_SEPARATOR . '../app/console', 'nemrod:elastica:populate', '--no-clear-cache')); if ($options['slice']) { $args[] = "--batch=" . $options['slice']; } if ($index) { $args[] = '--index=' . $index; } if ($type) { $args[] = '--type=' . $type; } $pb = new ProcessBuilder($args); $process = $pb->getProcess(); $process->setTimeout($maxTimeExecution); // run & transfer output to current output $process->run(function ($type, $buffer) use($output) { $output->writeln($buffer); }); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } exit; } $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $this->getContainer()->get('nemrod.elastica.populator')->populate($index, $type, $reset, $options, $output); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $server = $input->getOption('server'); $watch = $input->getOption('watch'); $io = new ConsoleIO($input, $output); $spress = $this->buildSpress($io, $input); $env = $spress['spress.config.values']['env']; $drafts = $spress['spress.config.values']['drafts']; $safe = $spress['spress.config.values']['safe']; $debug = $spress['spress.config.values']['debug']; $host = $spress['spress.config.values']['host']; $port = $spress['spress.config.values']['port']; $serverWatchExtension = $spress['spress.config.values']['server_watch_ext']; if ($debug === true) { $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } $this->startingMessage($io, $env, $drafts, $safe); $resultData = $spress->parse(); $this->resultMessage($io, $resultData); $sourceDir = $spress['spress.config.site_dir']; $destinationDir = $spress['spress.config.build_dir']; $rw = $this->buildResourceWatcher($sourceDir, $destinationDir); if ($server === true) { $documentroot = $destinationDir; $serverroot = __DIR__ . '/../../app/httpServer'; $server = new HttpServer($io, $serverroot, $documentroot, $port, $host); if ($watch === true) { $io->labelValue('Auto-regeneration', 'enabled'); $server->onBeforeRequest(function (ServerRequest $request) use($io, $input, $rw, $serverWatchExtension) { $resourceExtension = pathinfo($request->getPathFilename(), PATHINFO_EXTENSION); if (in_array($resourceExtension, $serverWatchExtension)) { $this->reParse($io, $input, $rw); } }); } $server->start(); } elseif ($watch) { $io->labelValue('Auto-regeneration', 'enabled'); $io->write('<comment>Press ctrl-c to stop.</comment>'); $io->newLine(); do { sleep(2); $this->reParse($io, $input, $rw); } while (true); } }
protected function runCommand(InputInterface $input, OutputInterface $output, $commandString, array $options = array(), $quiet = true) { $defaults = ['-e' => $input->getOption('env'), 'command' => $commandString]; if (!$input->isInteractive()) { $defaults['--no-interaction'] = true; } $command = $this->getApplication()->find($command); if ($quiet) { $oldVerbosity = $output->getVerbosity(); $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } $result = $command->run(new ArrayInput(array_merge($defaults, $options)), $output); if ($quiet) { $output->setVerbosity($oldVerbosity); } return $result; }
public function execute(InputInterface $input, OutputInterface $output) { $output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString()); $options = $input->getOptions(); if ($options['debug']) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } $config = Configuration::config($options['config']); $suite = $input->getArgument('suite'); $test = $input->getArgument('test'); if (!Configuration::isEmpty() && !$test && strpos($suite, $config['paths']['tests']) === 0) { list($matches, $suite, $test) = $this->matchTestFromFilename($suite, $config['paths']['tests']); } if ($options['group']) { $output->writeln(sprintf("[Groups] <info>%s</info> ", implode(', ', $options['group']))); } if ($input->getArgument('test')) { $options['steps'] = true; } $this->codecept = new \Codeception\Codecept((array) $options); if ($suite and $test) { $this->codecept->runSuite($suite, $test); } if (!$test) { $suites = $suite ? explode(',', $suite) : Configuration::suites(); $current_dir = Configuration::projectDir(); $executed = $this->runSuites($suites, $options['skip']); foreach ($config['include'] as $included_config_file) { Configuration::config($full_path = $current_dir . $included_config_file); $namespace = $this->currentNamespace(); $output->writeln("\n<fg=white;bg=magenta>\n[{$namespace}]: tests from {$full_path}\n</fg=white;bg=magenta>"); $suites = $suite ? explode(',', $suite) : Configuration::suites(); $executed += $this->runSuites($suites, $options['skip']); } if (!$executed) { throw new \RuntimeException(sprintf("Suite '%s' could not be found", implode(', ', $suites))); } } $this->codecept->printResult(); if (!$input->getOption('no-exit')) { if ($this->codecept->getResult()->failureCount() or $this->codecept->getResult()->errorCount()) { exit(1); } } }
/** * @inheritdoc */ protected function initialize(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->stdErr = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; self::$interactive = $input->isInteractive(); if (getenv('PLATFORMSH_CLI_DEBUG')) { $this->stdErr->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } // Tune error reporting based on the output verbosity. if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { error_reporting(E_ALL); } elseif ($output->getVerbosity() === OutputInterface::VERBOSITY_QUIET) { error_reporting(false); } else { error_reporting(E_PARSE); } $this->_deleteOldCaches(); }
/** * Main command function. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $output->writeln('<info>---- Jobeet2: Cleanup console command ----------</info>'); $em = $this->getEntityManager(null); $repo = $em->getRepository('Jobeet2Bundle:Job'); $output->writeln(sprintf('<info> > Current environment: "%s"</info>', $input->getOption('env'))); try { $cleanedJobs = $repo->cleanup($input->getOption('days')); if ($cleanedJobs > 0) { $output->writeln(sprintf('<info> > Successfully removed "%d" stale jobs from the database.</info>', $cleanedJobs)); } else { $output->writeln('<info> > Database is already clean, nothing to delete.</info>'); } $output->writeln('<info>---- Done --------------------------------------</info>'); } catch (\Exception $e) { $output->writeln(sprintf('<error>An error occured: %s</error>', $e->getMessage())); } }
/** * @inheritdoc */ protected function initialize(InputInterface $input, OutputInterface $output) { // Set up dependencies that are only needed once per command run. $this->output = $output; $this->input = $input; $this->stdErr = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; self::$interactive = $input->isInteractive(); if (self::$config->get('api.debug')) { $this->stdErr->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } // Tune error reporting based on the output verbosity. if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { error_reporting(E_ALL); } elseif ($output->getVerbosity() === OutputInterface::VERBOSITY_QUIET) { error_reporting(false); } else { error_reporting(E_PARSE | E_ERROR); } $this->promptLegacyMigrate(); }
/** * Hijack execute to turn off quiet * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return mixed */ protected function execute(InputInterface $input, OutputInterface $output) { // No being quiet allowed... if (true === ($this->wasQuiet = OutputInterface::VERBOSITY_QUIET === $output->getVerbosity())) { $output->setVerbosity(OutputInterface::VERBOSITY_NORMAL); } // Get the output format, if any if ($input->hasOption('format')) { if (empty($this->format = strtolower(trim($this->option('format'))))) { $this->format = null; } } // No header when quiet or formatted data output... if (null === $this->format && !$this->wasQuiet) { $this->writeHeader(); } // Do the execute $_result = parent::execute($input, $output); // Restore verbosity and return $this->wasQuiet && $output->setVerbosity(OutputInterface::VERBOSITY_NORMAL); return $_result; }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } /** @var ChannelRepository $repository */ /** @var SyncProcessor $processor */ /** @var BlockingJob $blockedJobsManager */ $connector = $input->getOption('connector'); $integrationId = $input->getOption('integration-id'); $batchSize = $input->getOption('transport-batch-size'); $connectorParameters = $this->getConnectorParameters($input); $entityManager = $this->getService('doctrine.orm.entity_manager'); $repository = $entityManager->getRepository('OroIntegrationBundle:Channel'); $logger = new OutputLogger($output); $entityManager->getConnection()->getConfiguration()->setSQLLogger(null); $blockedJobsManager = $this->getService('oro_integration.manager.blocking_job'); if ($this->isJobRunning($integrationId)) { $logger->warning('Job already running. Terminating....'); return self::STATUS_SUCCESS; } if ($integrationId) { $integration = $repository->getOrLoadById($integrationId); if (!$integration) { $logger->critical(sprintf('Integration with given ID "%d" not found', $integrationId)); return self::STATUS_FAILED; } if ($this->isBlockingJobRunning($integration, $blockedJobsManager)) { $logger->warning('Blocking jobs already running. Terminating....'); return self::STATUS_SUCCESS; } $exitCode = $this->processIntegration($logger, $integration, $batchSize, $connector, $connectorParameters); } else { $integrations = $repository->getConfiguredChannelsForSync(null, true); $exitCode = $this->processIntegrations($integrations); } $logger->notice('Completed'); return $exitCode; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); // check presence of action $modeOption = false; foreach (['dump', 'upload', 'download'] as $option) { $modeOption = $modeOption || $input->getOption($option) === true; } if (!$modeOption) { $output->writeln('<info>You must choose action: e.g --dump, --upload or --download</info>'); return 1; } $this->path = $this->getContainer()->getParameter('kernel.root_dir') . str_replace('//', '/', $input->getOption('path') . '/'); $locale = $input->getArgument('locale'); $outputFormat = $input->getOption('output-format'); $projectNamespace = $input->getArgument('project'); $namespaces = [$projectNamespace]; // TODO: incomment later // if ('Pro' != substr($projectNamespace, -3)) { // $namespaces[] = $projectNamespace . 'Pro'; // } if ($input->getOption('dump') === true) { foreach ($namespaces as $namespace) { $this->dump($namespace, $locale, $output, $outputFormat); } } if ($input->getOption('upload') === true) { $translationService = $this->getTranslationService($input, $output); $langPackDirs = []; foreach ($namespaces as $namespace) { $langPackDirs[$namespace] = $this->getLangPackDir($namespace); } $this->upload($translationService, $input->getOption('upload-mode'), $langPackDirs); } if ($input->getOption('download') === true) { $this->download($input, $output); } return 0; }