/** * Export current report as follows: * * 1. Display messages on CLI * 2. Run all formatters and display their text results on CLI * * If no formatter has been specified a default writer will be used depending * on the file extension given. Without a file extension a plain text writer * will be used. */ public function run() { $output = $this->command->getOutput(); $output->writeln(''); $output->writeln('---------------------'); $output->writeln('-- Report follows: --'); $output->writeln('---------------------'); $output->writeln(''); $formatter = new ConsoleMessageFormatter(); $console_report_text = $formatter->format($this->report); $output->writeln($console_report_text); $output->writeln(''); $output->writeln('---------------------'); $output->writeln('-- Export follows: --'); $output->writeln('---------------------'); $output->writeln(''); $default_formatter = array('location' => self::DEFAULT_EXPORT_LOCATION); $formatter_definitions = $this->parameters->get('formatters', array($default_formatter)); foreach ($formatter_definitions as $formatter_definition) { $params = new Parameters($formatter_definition); $location = $params->get('location', self::DEFAULT_EXPORT_LOCATION); if ($params->has('__class')) { $formatter_class = $params->get('__class'); } else { $formatter_class = $this->getFormatterByExtension($location); } $formatter = new $formatter_class(); $formatter->setParameters($params); $output->writeln('Starting export via "' . $formatter_class . '".'); $export_text = $formatter->format($this->report); $output->writeln($export_text); } $output->writeln(''); }
protected function configure() { parent::configure(); $this->setName('about'); $this->setDescription('Information about Environaut.'); $this->setHelp('Displays detailed information about Environaut.'); }
/** * Initializes the command just after the input has been validated. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); // necessary to register autoloader $config = $input->getOption('config'); if (!empty($config)) { if (!is_readable($config)) { throw new \InvalidArgumentException('Config file path "' . $config . '" is not readable.'); } $this->config_path = $config; if ($input->getOption('verbose')) { $output->writeln('<comment>Config file path specified: ' . $this->config_path . '</comment>'); } } else { $this->config_path = $this->getCurrentWorkingDirectory(); if ($input->getOption('verbose')) { $output->writeln('<comment>Config file path not specified, using "' . $this->config_path . '" as default lookup location.</comment>'); } } $config_handler_implementor = $input->getOption('config-handler'); if (empty($config_handler_implementor)) { $config_handler_implementor = 'Environaut\\Config\\ConfigHandler'; } $this->config_handler = new $config_handler_implementor(); $this->config_handler->addLocation($this->config_path); // TODO allow multiple locations for config option? // $config_reader->setLocations(array($this->config_path)); }
/** * @return \Symfony\Component\Console\Output\OutputInterface */ public function getOutputStream() { return $this->command->getOutput(); }