/** * @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 (!empty($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); }
/** * @see \Symfony\Component\Console\Command\Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $key = $input->getArgument('key'); $value = $input->getArgument('value'); if ($input->getOption('backup')) { $backup = true; } else { $backup = false; } if ($input->getOption('file')) { $file = $input->getOption('file'); } else { $file = 'config.yml'; } try { $yaml = new YamlUpdater($this->app, $file); if ($yaml->change($key, $value, $backup)) { $result = sprintf("New value for <info>%s: %s</info> was successful. File updated.", $key, $value); } 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>'); } $this->auditLog(__CLASS__, "Config value '{$key}: {$value}' set"); $output->writeln($result); }