Skip to content

Commit

Permalink
feat: Add option output to command get:sql-dump to set output file
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Aug 30, 2024
1 parent 337b320 commit 9414624
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Command/GetSqlDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Phabalicious\Command;

use Phabalicious\Configuration\ConfigurationService;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Exception\BlueprintTemplateNotFoundException;
use Phabalicious\Exception\FabfileNotFoundException;
use Phabalicious\Exception\FabfileNotReadableException;
Expand All @@ -10,8 +12,10 @@
use Phabalicious\Exception\MissingDockerHostConfigException;
use Phabalicious\Exception\ShellProviderNotFoundException;
use Phabalicious\Exception\TaskNotFoundInMethodException;
use Phabalicious\ShellProvider\LocalShellProvider;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

Expand All @@ -25,6 +29,13 @@ protected function configure()
->setDescription('Get a current dump of the database')
->setHelp('Gets a dump of the database and copies it to your local computer');
$this->setAliases(['getSQLDump']);
$this->addOption(
'output',
'o',
InputOption::VALUE_OPTIONAL,
'The file to copy the dump to',
''
);
parent::configure();
}

Expand Down Expand Up @@ -65,14 +76,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$shell->run(sprintf('rm %s', $file));
}
if ((count($files) > 0) && $input->getOption('output')) {
$local_shell = new LocalShellProvider($this->configuration->getLogger());
$local_shell->setHostConfig(new HostConfig([
'rootFolder' => getcwd(),
'shellExecutable' => '/bin/bash'
], $local_shell, $this->configuration));

$file = reset($files);
$target_file = $input->getOption('output');
$local_shell->run(sprintf('rm -f %s', $target_file));
$local_shell->run(sprintf('mv %s %s', $file, $target_file));

$files = [$target_file];
}

if (count($files) > 0) {
$io = new SymfonyStyle($input, $output);
$io->title('Copied dumps to:');
$io->listing($files);
}


return 0;
}
}

0 comments on commit 9414624

Please sign in to comment.