5 * Contains \Drupal\Console\Core\Command\Yaml\GetValueCommand.
8 namespace Drupal\Console\Core\Command\Yaml;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Yaml\Parser;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17 use Drupal\Console\Core\Utils\NestedArray;
19 class GetValueCommand extends Command
26 protected $nestedArray;
29 * GetValueCommand constructor.
31 * @param NestedArray $nestedArray
33 public function __construct(NestedArray $nestedArray)
35 $this->nestedArray = $nestedArray;
36 parent::__construct();
39 protected function configure()
42 ->setName('yaml:get:value')
43 ->setDescription($this->trans('commands.yaml.get.value.description'))
46 InputArgument::REQUIRED,
47 $this->trans('commands.yaml.get.value.arguments.yaml-file')
51 InputArgument::REQUIRED,
52 $this->trans('commands.yaml.get.value.arguments.yaml-key')
56 protected function execute(InputInterface $input, OutputInterface $output)
58 $io = new DrupalStyle($input, $output);
62 $yaml_file = $input->getArgument('yaml-file');
63 $yaml_key = $input->getArgument('yaml-key');
66 $yaml_parsed = $yaml->parse(file_get_contents($yaml_file), true);
67 } catch (\Exception $e) {
68 $io->error($this->trans('commands.yaml.merge.messages.error-parsing').': '.$e->getMessage());
72 if (empty($yaml_parsed)) {
75 $this->trans('commands.yaml.merge.messages.wrong-parse'),
81 $parents = explode(".", $yaml_key);
82 $yaml_value = $this->nestedArray->getValue($yaml_parsed, $parents, $key_exists);
87 $this->trans('commands.yaml.get.value.messages.invalid-key'),
94 $io->writeln($yaml_value);