/** * 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); }
protected function setUp() { $config = new Config($this->getConfigArray()); $this->input = new ArrayInput([]); $this->output = new StreamOutput(fopen('php://memory', 'a', false)); $this->output->setDecorated(false); $this->manager = new Manager($config, $this->input, $this->output); }
protected function configureIO(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--colors'))) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-colors'))) { $output->setDecorated(false); } parent::configureIO($input, $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; }
private function decorateOutput() { if ($this->output === null) { return; } $this->output->setDecorated(true); }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->setDecorated(true); $style = new OutputFormatterStyle('red'); $output->getFormatter()->setStyle('stacktrace', $style); $this->executeGenerateBootstrap($input, $output); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->setDecorated(true); $this->appState->setAreaCode('catalog'); $connection = $this->attributeResource->getConnection(); $attributeTables = $this->getAttributeTables(); $progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables)); $progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%'); $this->attributeResource->beginTransaction(); try { // Find and remove unused attributes foreach ($attributeTables as $attributeTable) { $progress->setMessage($attributeTable . ' '); $affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable); if (count($affectedIds) > 0) { $connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]); } $progress->advance(); } $this->attributeResource->commit(); $output->writeln(""); $output->writeln("<info>Unused product attributes successfully cleaned up:</info>"); $output->writeln("<comment> " . implode("\n ", $attributeTables) . "</comment>"); } catch (\Exception $exception) { $this->attributeResource->rollBack(); $output->writeln(""); $output->writeln("<error>{$exception->getMessage()}</error>"); } }
protected function execute(InputInterface $input, OutputInterface $output) { $output->setDecorated(true); $table = new Table($output); $table->setHeaders(['endpoint', 'method', 'controller', 'context', 'default_context']); $endpointOption = $input->getOption('endpoint'); $allRoutes = $this->getRoutes(); /** @var Route[][] $sortedRoutes */ $sortedRoutes = []; foreach ($allRoutes as $endpoint => $routes) { foreach ($routes as $route) { $sortedRoutes[$endpoint][$route->getMethod()] = $route; } ksort($sortedRoutes[$endpoint]); } foreach ($sortedRoutes as $endpoint => $routes) { if (count($endpointOption) !== 0 && !in_array($endpoint, $endpointOption, true)) { continue; } foreach ($routes as $route) { $table->addRow([$endpoint, $route->getMethod(), $route->getController(), implode(',', $route->getContext()), $route->includeDefaultContext() ? 'true' : 'false']); } } $table->render(); }
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) { $output->setDecorated(true); $username = $input->getOption('username'); $password = $input->getOption('password'); $plugin = $input->getOption('plugin'); $lastUpdate = $input->getOption('lastupdate'); $resource = 'piwik-' . ($plugin ? 'plugin-' . strtolower($plugin) : 'base'); $transifexApi = new API($username, $password); // remove all existing translation files in download path $files = glob($this->getDownloadPath() . DIRECTORY_SEPARATOR . '*.json'); array_map('unlink', $files); if (!$transifexApi->resourceExists($resource)) { $output->writeln("Skipping resource {$resource} as it doesn't exist on Transifex"); return; } $output->writeln("Fetching translations from Transifex for resource {$resource}"); $availableLanguages = LanguagesManagerApi::getInstance()->getAvailableLanguageNames(); $languageCodes = array(); foreach ($availableLanguages as $languageInfo) { $languageCodes[] = $languageInfo['code']; } $languageCodes = array_filter($languageCodes, function ($code) { return !in_array($code, array('en', 'dev')); }); try { $languages = $transifexApi->getAvailableLanguageCodes(); if (!empty($plugin)) { $languages = array_filter($languages, function ($language) { return LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language))); }); } } catch (AuthenticationFailedException $e) { $languages = $languageCodes; } /** @var ProgressBar $progress */ $progress = new ProgressBar($output, count($languages)); $progress->start(); $statistics = $transifexApi->getStatistics($resource); foreach ($languages as $language) { try { // if we have modification date given from statistics api compare it with given last update time to ignore not update resources if (LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language))) && isset($statistics->{$language})) { $lastupdated = strtotime($statistics->{$language}->last_update); if ($lastUpdate > $lastupdated) { $progress->advance(); continue; } } $translations = $transifexApi->getTranslations($resource, $language, true); file_put_contents($this->getDownloadPath() . DIRECTORY_SEPARATOR . str_replace('_', '-', strtolower($language)) . '.json', $translations); } catch (\Exception $e) { $output->writeln("Error fetching language file {$language}: " . $e->getMessage()); } $progress->advance(); } $progress->finish(); $output->writeln(''); }
protected function initialize(InputInterface $input, OutputInterface $output) { // Because colors are coolest ... $output->setDecorated(true); // TODO: Violation of law of demeter. // Since this is considered "framework layer" and has little churn... // Probably okay. $this->app = $this->getApplication()->getContainer(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $connection = $this->getDatabaseConnection($input); // If not explicitly set, disable ANSI which will break generated php. if ($input->hasParameterOption(['--ansi']) !== TRUE) { $output->setDecorated(FALSE); } $schema_tables = $input->getOption('schema-only'); $schema_tables = explode(',', $schema_tables); $output->writeln($this->generateScript($connection, $schema_tables), OutputInterface::OUTPUT_RAW); }
protected function runJob(CronJob $job, OutputInterface $output, EntityManager $em, $date = null) { $date = $date == null ? new \DateTime() : $date; $output->setDecorated(true); $output->writeln("<comment>Running " . $job->getCommand() . ": </comment>"); try { $commandToRun = $this->getApplication()->get($job->getCommand()); } catch (InvalidArgumentException $ex) { $output->writeln(" skipped (command no longer exists)"); $this->recordJobResult($em, $job, 0, "Command no longer exists", CronJobResult::SKIPPED); // No need to reschedule non-existant commands return; } $emptyInput = new ArgvInput(); $jobOutput = new MemoryWriter(); $jobStart = microtime(true); try { $returnCode = $commandToRun->execute($emptyInput, $jobOutput); } catch (\Exception $ex) { $returnCode = CronJobResult::FAILED; $jobOutput->writeln(""); $jobOutput->writeln("Job execution failed with exception " . get_class($ex) . ":"); $jobOutput->writeln($ex->__toString()); } $jobEnd = microtime(true); // Clamp the result to accepted values if ($returnCode < CronJobResult::RESULT_MIN || $returnCode > CronJobResult::RESULT_MAX) { $returnCode = CronJobResult::FAILED; } // Output the result $statusStr = "unknown"; if ($returnCode == CronJobResult::SKIPPED) { $statusStr = "skipped"; } elseif ($returnCode == CronJobResult::SUCCEEDED) { $statusStr = "succeeded"; } elseif ($returnCode == CronJobResult::FAILED) { $statusStr = "failed"; } $output->writeln($jobOutput->getOutput()); $durationStr = sprintf("%0.2f", $jobEnd - $jobStart); $output->writeln("{$statusStr} in {$durationStr} seconds"); // Record the result $this->recordJobResult($em, $job, $jobEnd - $jobStart, $jobOutput->getOutput(), $returnCode); // And update the job with it's next scheduled time $newTime = clone $date; $output->writeln('New Time : ' . $newTime->format(DATE_ATOM)); $newTime = $newTime->add(new \DateInterval($job->getInterval())); $output->writeln('New interval Time : ' . $newTime->format(DATE_ATOM)); $job->setNextRun($newTime); }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { try { $this->getDocumentManager()->getSchemaManager()->ensureIndexes(); $output->setDecorated(true); $cannedMessage = new CannedMessage(); $cannedMessage->setTitle($input->getArgument('title')); $cannedMessage->setContent($input->getArgument('content')); $this->getDocumentManager()->persist($cannedMessage); $this->getDocumentManager()->flush(array('safe' => true)); $output->write("Pronto", true); } catch (MongoCursorException $e) { $output->write($e->getMessage(), true); } }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $filesystem = $input->getArgument('filesystem'); $glob = $input->getArgument('glob'); $container = $this->getContainer(); $serviceId = sprintf('gaufrette.%s_filesystem', $filesystem); if (!$container->has($serviceId)) { throw new \RuntimeException(sprintf('There is no \'%s\' filesystem defined.', $filesystem)); } $filesystem = $container->get($serviceId); $keys = $filesystem->keys(); if (!empty($glob)) { $glob = new Glob($glob); $keys = $glob->filter($keys); } $count = count($keys); $output->writeln(sprintf('Bellow %s the <info>%s key%s</info> that where found:', $count > 1 ? 'are' : 'is', $count, $count > 1 ? 's' : '')); $output->setDecorated(true); foreach ($keys as $key) { $output->writeln(' - <info>' . $key . '</info>'); } }
/** * Configures the input and output instances based on the user arguments and options. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function configureIO(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--ansi'), true)) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-ansi'), true)) { $output->setDecorated(false); } if (true === $input->hasParameterOption(array('--no-interaction', '-n'), true)) { $input->setInteractive(false); } elseif (function_exists('posix_isatty')) { $inputStream = null; if ($input instanceof StreamableInputInterface) { $inputStream = $input->getStream(); } // This check ensures that calling QuestionHelper::setInputStream() works // To be removed in 4.0 (in the same time as QuestionHelper::setInputStream) if (!$inputStream && $this->getHelperSet()->has('question')) { $inputStream = $this->getHelperSet()->get('question')->getInputStream(false); } if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) { $input->setInteractive(false); } } if (true === $input->hasParameterOption(array('--quiet', '-q'), true)) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); $input->setInteractive(false); } else { if ($input->hasParameterOption('-vvv', true) || $input->hasParameterOption('--verbose=3', true) || $input->getParameterOption('--verbose', false, true) === 3) { $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } elseif ($input->hasParameterOption('-vv', true) || $input->hasParameterOption('--verbose=2', true) || $input->getParameterOption('--verbose', false, true) === 2) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } elseif ($input->hasParameterOption('-v', true) || $input->hasParameterOption('--verbose=1', true) || $input->hasParameterOption('--verbose', true) || $input->getParameterOption('--verbose', false, true)) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } } }
/** * Processes data from container and console input. * * @param InputInterface $input * @param OutputInterface $output */ public function process(InputInterface $input, OutputInterface $output) { $translator = $this->container->get('behat.translator'); $manager = $this->container->get('behat.formatter.manager'); $formats = array_map('trim', explode(',', $input->getOption('format') ?: $this->container->getParameter('behat.formatter.name'))); // load formatters translations foreach (require $this->container->getParameter('behat.paths.i18n') as $lang => $messages) { $translator->addResource('array', $messages, $lang, 'behat'); } // add user-defined formatter classes to manager foreach ($this->container->getParameter('behat.formatter.classes') as $name => $class) { $manager->addDispatcher(new FormatterDispatcher($name, $class)); } // init specified for run formatters foreach ($formats as $format) { $manager->initFormatter($format); } // set formatter options from behat.yml foreach ($parameters = $this->container->getParameter('behat.formatter.parameters') as $name => $value) { if ('output_path' === $name) { continue; } $manager->setFormattersParameter($name, $value); } $manager->setFormattersParameter('base_path', $this->container->getParameter('behat.paths.base')); $manager->setFormattersParameter('support_path', $this->container->getParameter('behat.paths.bootstrap')); $manager->setFormattersParameter('decorated', $output->isDecorated()); if ($input->getOption('verbose')) { $manager->setFormattersParameter('verbose', true); } if ($input->getOption('lang')) { $manager->setFormattersParameter('language', $input->getOption('lang')); } if (null !== ($ansi = $this->getSwitchValue($input, 'ansi'))) { $output->setDecorated($ansi); $manager->setFormattersParameter('decorated', $ansi); } if (null !== ($time = $this->getSwitchValue($input, 'time'))) { $manager->setFormattersParameter('time', $time); } if (null !== ($snippets = $this->getSwitchValue($input, 'snippets'))) { $manager->setFormattersParameter('snippets', $snippets); } if (null !== ($snippetsPaths = $this->getSwitchValue($input, 'snippets-paths'))) { $manager->setFormattersParameter('snippets_paths', $snippetsPaths); } if (null !== ($paths = $this->getSwitchValue($input, 'paths'))) { $manager->setFormattersParameter('paths', $paths); } if (null !== ($expand = $this->getSwitchValue($input, 'expand'))) { $manager->setFormattersParameter('expand', $expand); } if (null !== ($multiline = $this->getSwitchValue($input, 'multiline'))) { $manager->setFormattersParameter('multiline_arguments', $multiline); } if ($input->getOption('out')) { $outputs = $input->getOption('out'); } elseif (isset($parameters['output_path'])) { $outputs = $parameters['output_path']; } else { return; } if (false === strpos($outputs, ',')) { $out = $this->container->getParameter('behat.paths.base') . DIRECTORY_SEPARATOR . $outputs; // get realpath if (!file_exists($out)) { touch($out); $out = realpath($out); unlink($out); } else { $out = realpath($out); } $manager->setFormattersParameter('output_path', $out); $manager->setFormattersParameter('decorated', (bool) $this->getSwitchValue($input, 'ansi')); } else { foreach (array_map('trim', explode(',', $outputs)) as $i => $out) { if (!$out || 'null' === $out || 'false' === $out) { continue; } $out = $this->container->getParameter('behat.paths.base') . DIRECTORY_SEPARATOR . $out; // get realpath if (!file_exists($out)) { touch($out); $out = realpath($out); unlink($out); } else { $out = realpath($out); } $formatters = $manager->getFormatters(); if (isset($formatters[$i])) { $formatters[$i]->setParameter('output_path', $out); $formatters[$i]->setParameter('decorated', (bool) $this->getSwitchValue($input, 'ansi')); } } } }
/** * @param bool $color */ public function setColor($color) { $this->output->setDecorated($color); }
/** * Executes Run * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @throws \RuntimeException */ public function execute(InputInterface $input, OutputInterface $output) { $this->ensureCurlIsAvailable(); $this->options = $input->getOptions(); $this->output = $output; $config = Configuration::config($this->options['config']); if (!$this->options['colors']) { $this->options['colors'] = $config['settings']['colors']; } if (!$this->options['silent']) { $this->output->writeln(Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString()); } if ($this->options['no-colors']) { $this->output->setDecorated(!$this->options['no-colors']); } if ($this->options['colors']) { $this->output->setDecorated($this->options['colors']); } if ($this->options['debug']) { $this->output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } if ($this->options['no-colors']) { $this->options['colors'] = false; } $userOptions = array_intersect_key($this->options, array_flip($this->passedOptionKeys($input))); $userOptions = array_merge($userOptions, $this->booleanOptions($input, ['xml', 'html', 'json', 'tap', 'coverage', 'coverage-xml', 'coverage-html'])); $userOptions['verbosity'] = $this->output->getVerbosity(); if ($this->options['group']) { $userOptions['groups'] = $this->options['group']; } if ($this->options['skip-group']) { $userOptions['excludeGroups'] = $this->options['skip-group']; } if ($this->options['report']) { $userOptions['silent'] = true; } if ($this->options['coverage-xml'] or $this->options['coverage-html'] or $this->options['coverage-text']) { $this->options['coverage'] = true; } $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 ($this->options['group']) { $this->output->writeln(sprintf("[Groups] <info>%s</info> ", implode(', ', $this->options['group']))); } if ($input->getArgument('test')) { $this->options['steps'] = true; } if ($test) { $filter = $this->matchFilteredTestName($test); $userOptions['filter'] = $filter; } $this->codecept = new Codecept($userOptions); if ($suite and $test) { $this->codecept->run($suite, $test); } if (!$test) { $suites = $suite ? explode(',', $suite) : Configuration::suites(); $this->executed = $this->runSuites($suites, $this->options['skip']); if (!empty($config['include'])) { $current_dir = Configuration::projectDir(); $suites += $config['include']; $this->runIncludedSuites($config['include'], $current_dir); } if ($this->executed === 0) { throw new \RuntimeException(sprintf("Suite '%s' could not be found", implode(', ', $suites))); } } $this->codecept->printResult(); if (!$input->getOption('no-exit')) { if (!$this->codecept->getResult()->wasSuccessful()) { exit(1); } } }
/** * Prints available step definitions. * * @param Behat\Behat\Definition\Dumper $dumper definitions dumper * @param string $lang locale name * @param Symfony\Component\Console\Input\OutputInterface $output output console */ protected function demonstrateAvailableSteps(DefinitionDumper $dumper, $lang, OutputInterface $output) { $output->setDecorated(false); $output->write($dumper->dump($lang), false, OutputInterface::OUTPUT_RAW); }
/** * 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) { $name = $this->getCommandName($input); 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 (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; return is_numeric($statusCode) ? $statusCode : 0; }
/** * Configures formatters based on container, input and output configurations. * * @param FormatterManager $manager * @param InputInterface $input * @param OutputInterface $output */ protected function configureFormatters(FormatterManager $manager, InputInterface $input, OutputInterface $output) { $parameters = $this->container->getParameter('behat.formatter.parameters'); foreach ($parameters as $name => $value) { if ('output_path' === $name) { continue; } $manager->setFormattersParameter($name, $value); } $manager->setFormattersParameter('base_path', $this->container->getParameter('behat.paths.base')); $manager->setFormattersParameter('features_path', $this->container->getParameter('behat.paths.features')); $manager->setFormattersParameter('support_path', $this->container->getParameter('behat.paths.bootstrap')); $manager->setFormattersParameter('decorated', $output->isDecorated()); if ($input->getOption('verbose')) { $manager->setFormattersParameter('verbose', true); } if ($input->getOption('lang')) { $manager->setFormattersParameter('language', $input->getOption('lang')); } if (null !== ($ansi = $this->getSwitchValue($input, 'ansi'))) { $output->setDecorated($ansi); $manager->setFormattersParameter('decorated', $ansi); } if (null !== ($time = $this->getSwitchValue($input, 'time'))) { $manager->setFormattersParameter('time', $time); } if (null !== ($snippets = $this->getSwitchValue($input, 'snippets'))) { $manager->setFormattersParameter('snippets', $snippets); } if (null !== ($snippetsPaths = $this->getSwitchValue($input, 'snippets-paths'))) { $manager->setFormattersParameter('snippets_paths', $snippetsPaths); } if (null !== ($paths = $this->getSwitchValue($input, 'paths'))) { $manager->setFormattersParameter('paths', $paths); } if (null !== ($expand = $this->getSwitchValue($input, 'expand'))) { $manager->setFormattersParameter('expand', $expand); } if (null !== ($multiline = $this->getSwitchValue($input, 'multiline'))) { $manager->setFormattersParameter('multiline_arguments', $multiline); } }
protected function execute(InputInterface $input, OutputInterface $output) { $output->setDecorated(true); $start = microtime(true); /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); $languages = API::getInstance()->getAvailableLanguageNames(); $languageCodes = array(); foreach ($languages as $languageInfo) { $languageCodes[] = $languageInfo['code']; } $plugin = $input->getOption('plugin'); if (!$input->isInteractive()) { $output->writeln("(!) Non interactive mode: New languages will be skipped"); } $pluginList = array($plugin); if (empty($plugin)) { $pluginList = self::getPluginsInCore(); array_unshift($pluginList, ''); } else { $input->setOption('force', true); // force plugin only updates } foreach ($pluginList as $plugin) { $output->writeln(""); // fetch base or specific plugin $this->fetchTranslations($input, $output, $plugin); $files = _glob(FetchTranslations::getDownloadPath() . DIRECTORY_SEPARATOR . '*.json'); if (count($files) == 0) { $output->writeln("No translation updates available! Skipped."); continue; } $output->writeln("Starting to import new language files"); /** @var ProgressBar $progress */ $progress = new ProgressBar($output, count($files)); $progress->start(); foreach ($files as $filename) { $progress->advance(); $code = basename($filename, '.json'); if (!in_array($code, $languageCodes)) { if (!empty($plugin)) { continue; # never create a new language for plugin only } $createNewFile = false; if ($input->isInteractive()) { $createNewFile = $dialog->askConfirmation($output, "\nLanguage {$code} does not exist. Should it be added? ", false); } if (!$createNewFile) { continue; # do not create a new file for the language } @touch(PIWIK_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $code . '.json'); API::unsetInstance(); // unset language manager instance, so valid names are refetched } $command = $this->getApplication()->find('translations:set'); $arguments = array('command' => 'translations:set', '--code' => $code, '--file' => $filename, '--plugin' => $plugin); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, new NullOutput()); } $progress->finish(); $output->writeln(''); } $output->writeln("Finished in " . round(microtime(true) - $start, 3) . "s"); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { // If not explicitly set, disable ANSI which will break generated php. if ($input->hasParameterOption(['--ansi']) !== TRUE) { $output->setDecorated(FALSE); } $output->writeln($this->generateScript()); }
/** * {@inheritdoc} */ public function setDecorated($decorated) { $this->output->setDecorated($decorated); }
/** * Sets the decorated flag. * * @param bool $decorated Whether to decorate the messages */ public function setDecorated($decorated) { $this->original->setDecorated($decorated); }
/** * Configures the input and output instances based on the user arguments and options. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function configureIO(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--ansi'))) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-ansi'))) { $output->setDecorated(false); } if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); } elseif (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); } else { if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) { $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } } }
public function execute(InputInterface $input, OutputInterface $output) { $options = $input->getOptions(); if (!$options['silent']) { $output->writeln(Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString()); } if ($options['no-colors']) { $output->setDecorated(!$options['no-colors']); } if ($options['colors']) { $output->setDecorated($options['colors']); } $options = array_merge($options, $this->booleanOptions($input, ['xml','html','coverage','coverage-xml','coverage-html'])); if ($options['debug']) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } $options['verbosity'] = $output->getVerbosity(); $this->ensureCurlIsAvailable(); $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 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()->wasSuccessful()) { exit(1); } } }