/** * @see \Symfony\Component\Console\Command\Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $key = $input->getArgument('key'); if ($input->getOption('file')) { $file = $input->getOption('file'); } else { $file = 'config.yml'; } try { $yaml = new YamlUpdater($this->app, $file); $match = $yaml->get($key); if (null !== $match) { $result = sprintf("%s: %s", $key, $match); } else { $result = sprintf("<error>The key '%s' was not found in %s.</error>", $key, $file); } } catch (FileNotFoundException $e) { $result = sprintf("<error>Can't read file: %s.</error>", $file); } catch (ParseException $e) { $result = sprintf("<error>Invalid YAML in file: %s.</error>", $file); } catch (FilesystemException $e) { $result = sprintf('<error>' . $e->getMessage() . '</error>'); } $output->writeln($result); }