From 9f5acea29d365a8019ead9dcba30ab238b5dc1f0 Mon Sep 17 00:00:00 2001 From: enzo - Eduardo Garcia Date: Sat, 10 Jun 2017 06:55:23 +1000 Subject: [PATCH] Remove YAML command in behalf of new separate repository https://github.com/weknowinc/drupal-console-yaml (#167) * [chain] Avoid overwrite chain command options with global/default options * Revert "[chain] Avoid overwrite chain command options with global/default options" This reverts commit 109679411bd910e7d25e5b009bfe3538eb99b77c. * [chain] Avoid overwrite chain command options with global/default options * Remove YAML command in behalf of new separate repository https://github.com/weknowinc/drupal-console-yaml --- config/dist/aliases.yml | 10 - services.yml | 34 ---- src/Command/Yaml/DiffCommand.php | 242 ------------------------ src/Command/Yaml/GetValueCommand.php | 97 ---------- src/Command/Yaml/MergeCommand.php | 220 --------------------- src/Command/Yaml/SplitCommand.php | 240 ----------------------- src/Command/Yaml/UnsetKeyCommand.php | 110 ----------- src/Command/Yaml/UpdateKeyCommand.php | 116 ------------ src/Command/Yaml/UpdateValueCommand.php | 116 ------------ 9 files changed, 1185 deletions(-) delete mode 100644 src/Command/Yaml/DiffCommand.php delete mode 100644 src/Command/Yaml/GetValueCommand.php delete mode 100644 src/Command/Yaml/MergeCommand.php delete mode 100644 src/Command/Yaml/SplitCommand.php delete mode 100644 src/Command/Yaml/UnsetKeyCommand.php delete mode 100644 src/Command/Yaml/UpdateKeyCommand.php delete mode 100644 src/Command/Yaml/UpdateValueCommand.php diff --git a/config/dist/aliases.yml b/config/dist/aliases.yml index 5823ad3..a9d45c2 100644 --- a/config/dist/aliases.yml +++ b/config/dist/aliases.yml @@ -156,13 +156,3 @@ commands: - vdi views:enable: - ve - yaml:diff: - - yd - yaml:merge: - - ym - yaml:split: - - ys - yaml:update:key: - - yu - yaml:update:value: - - yuv diff --git a/services.yml b/services.yml index 09f1177..076a514 100644 --- a/services.yml +++ b/services.yml @@ -83,40 +83,6 @@ services: arguments: ['@console.configuration_manager'] tags: - { name: drupal.command } - console.yaml_diff: - class: Drupal\Console\Core\Command\Yaml\DiffCommand - arguments: ['@console.nested_array'] - tags: - - { name: drupal.command } - console.yaml_get_value: - class: Drupal\Console\Core\Command\Yaml\GetValueCommand - arguments: ['@console.nested_array'] - tags: - - { name: drupal.command } - console.yaml_merge: - class: Drupal\Console\Core\Command\Yaml\MergeCommand - tags: - - { name: drupal.command } - console.yaml_split: - class: Drupal\Console\Core\Command\Yaml\SplitCommand - arguments: ['@console.nested_array'] - tags: - - { name: drupal.command } - console.yaml_update_key: - class: Drupal\Console\Core\Command\Yaml\UpdateKeyCommand - arguments: ['@console.nested_array'] - tags: - - { name: drupal.command } - console.yaml_update_value: - class: Drupal\Console\Core\Command\Yaml\UpdateValueCommand - arguments: ['@console.nested_array'] - tags: - - { name: drupal.command } - console.yaml_unset_key: - class: Drupal\Console\Core\Command\Yaml\UnsetKeyCommand - arguments: ['@console.nested_array'] - tags: - - { name: drupal.command } # DrupalConsoleCore Generators console.init_generator: class: Drupal\Console\Core\Generator\InitGenerator diff --git a/src/Command/Yaml/DiffCommand.php b/src/Command/Yaml/DiffCommand.php deleted file mode 100644 index 47192f7..0000000 --- a/src/Command/Yaml/DiffCommand.php +++ /dev/null @@ -1,242 +0,0 @@ -nestedArray = $nestedArray; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('yaml:diff') - ->setDescription($this->trans('commands.yaml.diff.description')) - ->addArgument( - 'yaml-left', - InputArgument::REQUIRED, - $this->trans('commands.yaml.diff.arguments.yaml-left') - ) - ->addArgument( - 'yaml-right', - InputArgument::REQUIRED, - $this->trans('commands.yaml.diff.arguments.yaml-right') - ) - ->addOption( - 'stats', - false, - InputOption::VALUE_NONE, - $this->trans('commands.yaml.diff.options.stats') - ) - ->addOption( - 'negate', - false, - InputOption::VALUE_NONE, - $this->trans('commands.yaml.diff.options.negate') - ) - ->addOption( - 'limit', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.yaml.diff.options.limit') - ) - ->addOption( - 'offset', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.yaml.diff.options.offset') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - - $yaml_left = $input->getArgument('yaml-left'); - $yaml_right = $input->getArgument('yaml-right'); - - $stats = $input->getOption('stats'); - - $negate = $input->getOption('negate'); - - $limit = $input->getOption('limit'); - $offset = $input->getOption('offset'); - - if ($negate == 1 || $negate == 'TRUE') { - $negate = true; - } else { - $negate = false; - } - - try { - $yamlLeftParsed = $yaml->parse(file_get_contents($yaml_left)); - - if (empty($yamlLeftParsed)) { - $io->error( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_left - ) - ); - } - - $yamlRightParsed = $yaml->parse(file_get_contents($yaml_right)); - - if (empty($yamlRightParsed)) { - $io->error( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_right - ) - ); - } - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-parsing').': '.$e->getMessage()); - - return; - } - - $statistics = ['total' => 0, 'equal'=> 0 , 'diff' => 0]; - $diff = $this->nestedArray->arrayDiff($yamlLeftParsed, $yamlRightParsed, $negate, $statistics); - print_r($diff); - - if ($stats) { - $io->info( - sprintf( - $this->trans('commands.yaml.diff.messages.total'), - $statistics['total'] - ) - ); - - $io->info( - sprintf( - $this->trans('commands.yaml.diff.messages.diff'), - $statistics['diff'] - ) - ); - - $io->info( - sprintf( - $this->trans('commands.yaml.diff.messages.equal'), - $statistics['equal'] - ) - ); - - return; - } - // FLAT YAML file to display full yaml to be used with command yaml:update:key or yaml:update:value - $diffFlatten = []; - $keyFlatten = ''; - $this->nestedArray->yamlFlattenArray($diff, $diffFlatten, $keyFlatten); - - if ($limit !== null) { - if (!$offset) { - $offset = 0; - } - $diffFlatten = array_slice($diffFlatten, $offset, $limit); - } - - $tableHeader = [ - $this->trans('commands.yaml.diff.messages.key'), - $this->trans('commands.yaml.diff.messages.value'), - ]; - - $tableRows = []; - foreach ($diffFlatten as $yamlKey => $yamlValue) { - $tableRows[] = [ - $yamlKey, - $yamlValue - ]; - print $yamlKey . "\n"; - print $yamlValue . "\n"; - } - - $io->table($tableHeader, $tableRows, 'compact'); - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $validator_filename = function ($value) use ($io) { - if (!strlen(trim($value)) || !is_file($value)) { - $io->error($this->trans('commands.common.errors.invalid-file-path')); - - return false; - } - - return $value; - }; - - // --yaml-left option - $yaml_left = $input->getArgument('yaml-left'); - if (!$yaml_left) { - while (true) { - $yaml_left = $io->ask( - $this->trans('commands.yaml.diff.questions.yaml-left'), - null, - $validator_filename - ); - - if ($yaml_left) { - break; - } - } - - $input->setArgument('yaml-left', $yaml_left); - } - - // --yaml-right option - $yaml_right = $input->getArgument('yaml-right'); - if (!$yaml_right) { - while (true) { - $yaml_right = $io->ask( - $this->trans('commands.yaml.diff.questions.yaml-right'), - null, - $validator_filename - ); - - if ($yaml_right) { - break; - } - } - - $input->setArgument('yaml-right', $yaml_right); - } - } -} diff --git a/src/Command/Yaml/GetValueCommand.php b/src/Command/Yaml/GetValueCommand.php deleted file mode 100644 index e389dc3..0000000 --- a/src/Command/Yaml/GetValueCommand.php +++ /dev/null @@ -1,97 +0,0 @@ -nestedArray = $nestedArray; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('yaml:get:value') - ->setDescription($this->trans('commands.yaml.get.value.description')) - ->addArgument( - 'yaml-file', - InputArgument::REQUIRED, - $this->trans('commands.yaml.get.value.arguments.yaml-file') - ) - ->addArgument( - 'yaml-key', - InputArgument::REQUIRED, - $this->trans('commands.yaml.get.value.arguments.yaml-key') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - - $yaml_file = $input->getArgument('yaml-file'); - $yaml_key = $input->getArgument('yaml-key'); - - try { - $yaml_parsed = $yaml->parse(file_get_contents($yaml_file), true); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-parsing').': '.$e->getMessage()); - return; - } - - if (empty($yaml_parsed)) { - $io->info( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_file - ) - ); - } else { - $key_exists = null; - $parents = explode(".", $yaml_key); - $yaml_value = $this->nestedArray->getValue($yaml_parsed, $parents, $key_exists); - - if (!$key_exists) { - $io->info( - sprintf( - $this->trans('commands.yaml.get.value.messages.invalid-key'), - $yaml_key, - $yaml_file - ) - ); - } - - $io->writeln($yaml_value); - } - } -} diff --git a/src/Command/Yaml/MergeCommand.php b/src/Command/Yaml/MergeCommand.php deleted file mode 100644 index da655a7..0000000 --- a/src/Command/Yaml/MergeCommand.php +++ /dev/null @@ -1,220 +0,0 @@ -setName('yaml:merge') - ->setDescription($this->trans('commands.yaml.merge.description')) - ->addArgument( - 'yaml-destination', - InputArgument::REQUIRED, - $this->trans('commands.yaml.merge.arguments.yaml-destination') - ) - ->addArgument( - 'yaml-files', - InputArgument::IS_ARRAY, - $this->trans('commands.yaml.merge.arguments.yaml-files') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - $dumper = new Dumper(); - - $final_yaml = []; - $yaml_destination = realpath($input->getArgument('yaml-destination')); - $yaml_files = $input->getArgument('yaml-files'); - - if (!$yaml_destination) { - $fs = new Filesystem(); - try { - $fs->touch($input->getArgument('yaml-destination')); - $yaml_destination = realpath($input->getArgument('yaml-destination')); - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-writing'), - $e->getMessage() - ) - ); - - return; - } - } - - if (count($yaml_files) < 2) { - $io->error($this->trans('commands.yaml.merge.messages.two-files-required')); - - return; - } - - foreach ($yaml_files as $yaml_file) { - try { - $yaml_parsed = $yaml->parse(file_get_contents($yaml_file)); - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-parsing'), - $e->getMessage() - ) - ); - - return; - } - - if (empty($yaml_parsed)) { - $io->error( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_file - ) - ); - } - - // Merge arrays - $final_yaml = array_replace_recursive($final_yaml, $yaml_parsed); - } - - try { - $yaml = $dumper->dump($final_yaml, 10); - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-generating'), - $e->getMessage() - ) - ); - - return; - } - - try { - file_put_contents($yaml_destination, $yaml); - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-writing'), - $e->getMessage() - ) - ); - - return; - } - - $io->success( - sprintf( - $this->trans('commands.yaml.merge.messages.merged'), - $yaml_destination - ) - ); - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $validator_filename = function ($value) use ($io) { - if (!strlen(trim($value)) || !is_file($value)) { - $io->error($this->trans('commands.common.errors.invalid-file-path')); - - return false; - } - - return $value; - }; - - // --yaml-destination option - $yaml_destination = $input->getArgument('yaml-destination'); - if (!$yaml_destination) { - while (true) { - $yaml_destination = $io->ask( - $this->trans('commands.yaml.merge.questions.yaml-destination'), - '', - $validator_filename - ); - - if ($yaml_destination) { - break; - } - } - - $input->setArgument('yaml-destination', $yaml_destination); - } - - $yaml_files = $input->getArgument('yaml-files'); - if (!$yaml_files) { - $yaml_files = []; - - while (true) { - // Set the string key based on among files provided - if (count($yaml_files) >= 2) { - $questionStringKey = 'commands.yaml.merge.questions.other-file'; - } else { - $questionStringKey = 'commands.yaml.merge.questions.file'; - } - - $yaml_file = $io->ask( - $this->trans($questionStringKey), - '', - function ($file) use ($yaml_files, $io) { - if (count($yaml_files) < 2 && empty($file)) { - $io->error($this->trans('commands.yaml.merge.questions.invalid-file')); - return false; - } elseif (!empty($file) && in_array($file, $yaml_files)) { - $io->error( - sprintf($this->trans('commands.yaml.merge.questions.file-already-added'), $file) - ); - - return false; - } elseif ($file == '') { - return true; - } else { - return $file; - } - } - ); - - if ($yaml_file && !is_string($yaml_file)) { - break; - } - - if ($yaml_file) { - $yaml_files[] = realpath($yaml_file); - } - } - - $input->setArgument('yaml-files', $yaml_files); - } - } -} diff --git a/src/Command/Yaml/SplitCommand.php b/src/Command/Yaml/SplitCommand.php deleted file mode 100644 index a1d066c..0000000 --- a/src/Command/Yaml/SplitCommand.php +++ /dev/null @@ -1,240 +0,0 @@ -nestedArray = $nestedArray; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('yaml:split') - ->setDescription($this->trans('commands.yaml.split.description')) - ->addArgument( - 'yaml-file', - InputArgument::REQUIRED, - $this->trans('commands.yaml.split.value.arguments.yaml-file') - ) - ->addOption( - 'indent-level', - false, - InputOption::VALUE_REQUIRED, - $this->trans('commands.yaml.split.options.indent-level') - ) - ->addOption( - 'file-output-prefix', - false, - InputOption::VALUE_REQUIRED, - $this->trans('commands.yaml.split.options.file-output-prefix') - ) - ->addOption( - 'file-output-suffix', - false, - InputOption::VALUE_REQUIRED, - $this->trans('commands.yaml.split.options.file-output-suffix') - ) - ->addOption( - 'starting-key', - false, - InputOption::VALUE_REQUIRED, - $this->trans('commands.yaml.split.options.starting-key') - ) - ->addOption( - 'exclude-parents-key', - false, - InputOption::VALUE_NONE, - $this->trans('commands.yaml.split.options.exclude-parents-key') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - - $yaml_file = $input->getArgument('yaml-file'); - $indent_level = $input->getOption('indent-level'); - $exclude_parents_key = $input->getOption('exclude-parents-key'); - $starting_key = $input->getOption('starting-key'); - $file_output_prefix = $input->getOption('file-output-prefix'); - $file_output_suffix = $input->getOption('file-output-suffix'); - - if ($exclude_parents_key == 1 || $exclude_parents_key == 'TRUE') { - $exclude_parents_key = true; - } else { - $exclude_parents_key = false; - } - - try { - $yaml_file_parsed = $yaml->parse(file_get_contents($yaml_file)); - - if (empty($yaml_file_parsed)) { - $io->error( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_file - ) - ); - - return; - } - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-parsing'), - $e->getMessage() - ) - ); - - return; - } - - if ($starting_key) { - $parents = explode(".", $starting_key); - if ($this->nestedArray->keyExists($yaml_file_parsed, $parents)) { - $yaml_file_parsed = $this->nestedArray->getValue($yaml_file_parsed, $parents); - } else { - $io->error($this->trans('commands.yaml.merge.messages.invalid-key')); - } - - if ($indent_level == 0) { - $yaml_split[$starting_key] = $yaml_file_parsed; - } - } else { - // Set minimum level to split - $indent_level = empty($indent_level) ? 1 : $indent_level; - - $yaml_split = []; - $key_flatten = ''; - $initial_level = 1; - - $this->nestedArray->yamlSplitArray($yaml_file_parsed, $yaml_split, $indent_level, $key_flatten, $initial_level, $exclude_parents_key); - } - - $this->writeSplittedFile($yaml_split, $file_output_prefix, $file_output_suffix, $io); - } - - protected function writeSplittedFile($yaml_splitted, $file_output_prefix = '', $file_output_suffix = '', DrupalStyle $io) - { - $dumper = new Dumper(); - - $io->info($this->trans('commands.yaml.split.messages.generating-split')); - - foreach ($yaml_splitted as $key => $value) { - if ($file_output_prefix) { - $key = $file_output_prefix . '.' . $key; - } - - if ($file_output_suffix) { - $key.= '.' . $file_output_suffix; - } - $filename = $key . '.yml'; - - try { - $yaml = $dumper->dump($value, 10); - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-generating'), - $e->getMessage() - ) - ); - - return; - } - - try { - file_put_contents($filename, $yaml); - } catch (\Exception $e) { - $io->error( - sprintf( - '%s: %s', - $this->trans('commands.yaml.merge.messages.error-writing'), - $e->getMessage() - ) - ); - - return; - } - - $io->success( - sprintf( - $this->trans('commands.yaml.split.messages.split-generated'), - $filename - ) - ); - } - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $validator_filename = function ($value) use ($io) { - if (!strlen(trim($value)) || !is_file($value)) { - $io->error($this->trans('commands.common.errors.invalid-file-path')); - - return false; - } - - return $value; - }; - - // --yaml-left option - $yaml_file = $input->getArgument('yaml-file'); - if (!$yaml_file) { - while (true) { - $yaml_file = $io->ask( - $this->trans('commands.yaml.diff.questions.yaml-left'), - '', - $validator_filename - ); - - if ($yaml_file) { - break; - } - } - - $input->setArgument('yaml-file', $yaml_file); - } - } -} diff --git a/src/Command/Yaml/UnsetKeyCommand.php b/src/Command/Yaml/UnsetKeyCommand.php deleted file mode 100644 index 3b36a78..0000000 --- a/src/Command/Yaml/UnsetKeyCommand.php +++ /dev/null @@ -1,110 +0,0 @@ -nestedArray = $nestedArray; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('yaml:unset:key') - ->setDescription($this->trans('commands.yaml.unset.key.description')) - ->addArgument( - 'yaml-file', - InputArgument::REQUIRED, - $this->trans('commands.yaml.unset.value.arguments.yaml-file') - ) - ->addArgument( - 'yaml-key', - InputArgument::REQUIRED, - $this->trans('commands.yaml.unset.value.arguments.yaml-key') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - $dumper = new Dumper(); - - $yaml_file = $input->getArgument('yaml-file'); - $yaml_key = $input->getArgument('yaml-key'); - - try { - $yaml_parsed = $yaml->parse(file_get_contents($yaml_file)); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-parsing').': '.$e->getMessage()); - - return; - } - - if (empty($yaml_parsed)) { - $io->info( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_file - ) - ); - } - - $parents = explode(".", $yaml_key); - $this->nestedArray->unsetValue($yaml_parsed, $parents); - - try { - $yaml = $dumper->dump($yaml_parsed, 10); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-generating').': '.$e->getMessage()); - - return; - } - - try { - file_put_contents($yaml_file, $yaml); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-writing').': '.$e->getMessage()); - - return; - } - - $io->info( - sprintf( - $this->trans('commands.yaml.unset.value.messages.unset'), - $yaml_file - ) - ); - } -} diff --git a/src/Command/Yaml/UpdateKeyCommand.php b/src/Command/Yaml/UpdateKeyCommand.php deleted file mode 100644 index 7f6410a..0000000 --- a/src/Command/Yaml/UpdateKeyCommand.php +++ /dev/null @@ -1,116 +0,0 @@ -nestedArray = $nestedArray; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('yaml:update:key') - ->setDescription($this->trans('commands.yaml.update.key.description')) - ->addArgument( - 'yaml-file', - InputArgument::REQUIRED, - $this->trans('commands.yaml.update.value.arguments.yaml-file') - ) - ->addArgument( - 'yaml-key', - InputArgument::REQUIRED, - $this->trans('commands.yaml.update.value.arguments.yaml-key') - ) - ->addArgument( - 'yaml-new-key', - InputArgument::REQUIRED, - $this->trans('commands.yaml.update.value.arguments.yaml-new-key') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - $dumper = new Dumper(); - - $yaml_file = $input->getArgument('yaml-file'); - $yaml_key = $input->getArgument('yaml-key'); - $yaml_new_key = $input->getArgument('yaml-new-key'); - - try { - $yaml_parsed = $yaml->parse(file_get_contents($yaml_file)); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-parsing').': '.$e->getMessage()); - - return; - } - - if (empty($yaml_parsed)) { - $io->info( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_file - ) - ); - } - - $parents = explode(".", $yaml_key); - $this->nestedArray->replaceKey($yaml_parsed, $parents, $yaml_new_key); - - try { - $yaml = $dumper->dump($yaml_parsed, 10); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-generating').': '.$e->getMessage()); - - return; - } - - try { - file_put_contents($yaml_file, $yaml); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-writing').': '.$e->getMessage()); - - return; - } - - $io->info( - sprintf( - $this->trans('commands.yaml.update.value.messages.updated'), - $yaml_file - ) - ); - } -} diff --git a/src/Command/Yaml/UpdateValueCommand.php b/src/Command/Yaml/UpdateValueCommand.php deleted file mode 100644 index db23b92..0000000 --- a/src/Command/Yaml/UpdateValueCommand.php +++ /dev/null @@ -1,116 +0,0 @@ -nestedArray = $nestedArray; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('yaml:update:value') - ->setDescription($this->trans('commands.yaml.update.value.description')) - ->addArgument( - 'yaml-file', - InputArgument::REQUIRED, - $this->trans('commands.yaml.update.value.arguments.yaml-file') - ) - ->addArgument( - 'yaml-key', - InputArgument::REQUIRED, - $this->trans('commands.yaml.update.value.arguments.yaml-key') - ) - ->addArgument( - 'yaml-value', - InputArgument::REQUIRED, - $this->trans('commands.yaml.update.value.arguments.yaml-value') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $yaml = new Parser(); - $dumper = new Dumper(); - - $yaml_file = $input->getArgument('yaml-file'); - $yaml_key = $input->getArgument('yaml-key'); - $yaml_value = $input->getArgument('yaml-value'); - - - try { - $yaml_parsed = $yaml->parse(file_get_contents($yaml_file)); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-parsing').': '.$e->getMessage()); - return; - } - - if (empty($yaml_parsed)) { - $io->info( - sprintf( - $this->trans('commands.yaml.merge.messages.wrong-parse'), - $yaml_file - ) - ); - } - - $parents = explode(".", $yaml_key); - $this->nestedArray->setValue($yaml_parsed, $parents, $yaml_value, true); - - try { - $yaml = $dumper->dump($yaml_parsed, 10); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-generating').': '.$e->getMessage()); - - return; - } - - try { - file_put_contents($yaml_file, $yaml); - } catch (\Exception $e) { - $io->error($this->trans('commands.yaml.merge.messages.error-writing').': '.$e->getMessage()); - - return; - } - - $io->info( - sprintf( - $this->trans('commands.yaml.update.value.messages.updated'), - $yaml_file - ) - ); - } -}