-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented list:backups and interact of get command (#91)
- Loading branch information
1 parent
8147929
commit fd69e33
Showing
11 changed files
with
474 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Nanbando\Bundle\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* Lists available backups. | ||
*/ | ||
class ListBackupsCommand extends BaseServerCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('list:backups') | ||
->addOption('server', 's', InputOption::VALUE_REQUIRED, 'Where should the command be called.', 'local') | ||
->addOption('remote', 'r', InputOption::VALUE_NONE, 'Lists backups on remote storage.') | ||
->setDescription('List all available backups.') | ||
->setHelp( | ||
<<<EOT | ||
The <info>{$this->getName()}</info> command lists all available backups from local. | ||
With the options <info>-s</info> or <info>-r</info> lists backups on servers or remote storage. | ||
EOT | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getServerName(InputInterface $input) | ||
{ | ||
return $input->getOption('server'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getCommandOptions(InputInterface $input) | ||
{ | ||
return ['remote' => $input->getOption('remote')]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Nanbando\Core\Server\Command\Local; | ||
|
||
use Nanbando\Core\Server\Command\CommandInterface; | ||
use Nanbando\Core\Storage\StorageInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Lists local backups. | ||
*/ | ||
class LocalListBackupsCommand implements CommandInterface | ||
{ | ||
/** | ||
* @var StorageInterface | ||
*/ | ||
private $storage; | ||
|
||
/** | ||
* @var OutputInterface | ||
*/ | ||
private $output; | ||
|
||
/** | ||
* @param StorageInterface $storage | ||
* @param OutputInterface $output | ||
*/ | ||
public function __construct(StorageInterface $storage, OutputInterface $output) | ||
{ | ||
$this->storage = $storage; | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
// do nothing | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(array $options = []) | ||
{ | ||
$remote = array_key_exists('remote', $options) ? $options['remote'] : false; | ||
$files = $this->getFiles($remote); | ||
|
||
foreach ($files as $file) { | ||
$this->output->writeln($file); | ||
} | ||
} | ||
|
||
/** | ||
* Returns local of remote files. | ||
* | ||
* @param bool $remote | ||
* | ||
* @return string[] | ||
*/ | ||
private function getFiles($remote) | ||
{ | ||
if ($remote) { | ||
return $this->storage->remoteListing(); | ||
} | ||
|
||
return $this->storage->localListing(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Nanbando\Core\Server\Command\Ssh; | ||
|
||
use Nanbando\Core\Server\Command\CommandInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Lists ssh backups. | ||
*/ | ||
class SshListBackupsCommand implements CommandInterface | ||
{ | ||
/** | ||
* @var SshConnection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @var OutputInterface | ||
*/ | ||
private $output; | ||
|
||
/** | ||
* @param SshConnection $connection | ||
* @param OutputInterface $output | ||
*/ | ||
public function __construct(SshConnection $connection, OutputInterface $output) | ||
{ | ||
$this->connection = $connection; | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
// do nothing | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(array $options = []) | ||
{ | ||
$parameters = []; | ||
if (array_key_exists('remote', $options) && $options['remote']) { | ||
$parameters['-r'] = ''; | ||
} | ||
|
||
$this->connection->executeNanbando( | ||
'list:backups', | ||
$parameters, | ||
function ($line) { | ||
$this->output->write($line); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Unit\Bundle\Command; | ||
|
||
use Nanbando\Bundle\Command\GetCommand; | ||
use Nanbando\Core\Server\Command\CommandInterface; | ||
use Nanbando\Core\Server\ServerRegistry; | ||
use Prophecy\Argument; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Tests for class "GetCommand". | ||
*/ | ||
class GetCommandTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ServerRegistry | ||
*/ | ||
private $serverRegistry; | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->serverRegistry = $this->prophesize(ServerRegistry::class); | ||
$this->container = $this->prophesize(ContainerInterface::class); | ||
} | ||
|
||
private function getCommandTester() | ||
{ | ||
$this->container->get('nanbando.server_registry')->willReturn($this->serverRegistry->reveal()); | ||
|
||
$command = new GetCommand(); | ||
$command->setContainer($this->container->reveal()); | ||
|
||
$application = new Application(); | ||
$application->add($command); | ||
|
||
$command = $application->find('get'); | ||
|
||
return new CommandTester($command); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$command = $this->prophesize(CommandInterface::class); | ||
$command->interact(Argument::type(InputInterface::class), Argument::type(OutputInterface::class)) | ||
->shouldBeCalled(); | ||
$command->execute(['name' => '2017-01-01-12-00-00'])->shouldBeCalled(); | ||
|
||
$this->serverRegistry->getCommand('local', 'get')->willReturn($command->reveal()); | ||
|
||
$commandTester = $this->getCommandTester(); | ||
$commandTester->execute(['source-server' => 'local', 'name' => '2017-01-01-12-00-00']); | ||
} | ||
} |
Oops, something went wrong.