Skip to content

Commit 64c4f8d

Browse files
isramvjmolivas
authored andcommitted
#3228: command requires target file to exist before merge (#159)
1 parent feeac74 commit 64c4f8d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Command/Yaml/MergeCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Command\Command;
1616
use Drupal\Console\Core\Command\Shared\CommandTrait;
1717
use Drupal\Console\Core\Style\DrupalStyle;
18+
use Symfony\Component\Filesystem\Filesystem;
1819

1920
class MergeCommand extends Command
2021
{
@@ -48,6 +49,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
4849
$yaml_destination = realpath($input->getArgument('yaml-destination'));
4950
$yaml_files = $input->getArgument('yaml-files');
5051

52+
if(!$yaml_destination) {
53+
$fs = new Filesystem();
54+
try {
55+
$fs->touch($input->getArgument('yaml-destination'));
56+
$yaml_destination = realpath($input->getArgument('yaml-destination'));
57+
} catch (\Exception $e) {
58+
$io->error(
59+
sprintf(
60+
'%s: %s',
61+
$this->trans('commands.yaml.merge.messages.error-writing'),
62+
$e->getMessage()
63+
)
64+
);
65+
66+
return;
67+
}
68+
}
69+
5170
if (count($yaml_files) < 2) {
5271
$io->error($this->trans('commands.yaml.merge.messages.two-files-required'));
5372

0 commit comments

Comments
 (0)