Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
Merge branch '16-ls-name-optional' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyshaw committed Dec 18, 2015
2 parents d431d7e + 7985b9a commit 28fa9ba
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Meanbee/Magedbm/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function configure()
->setDescription('List available backups')
->addArgument(
'name',
InputArgument::REQUIRED,
InputArgument::OPTIONAL,
'Project identifier'
)
->addOption(
Expand Down Expand Up @@ -53,15 +53,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
$s3 = $this->getS3Client($input->getOption('region'));
$config = $this->getConfig($input);

$name = $input->getArgument('name') ?: '';

try {
$results = $s3->getIterator(
'ListObjects',
array('Bucket' => $config['bucket'], 'Prefix' => $input->getArgument('name'))
array('Bucket' => $config['bucket'], 'Prefix' => $name)
);

$names = array();
foreach ($results as $item) {
$itemKeyChunks = explode('/', $item['Key']);
$this->getOutput()->writeln(sprintf('%s %dMB', array_pop($itemKeyChunks), $item['Size'] / 1024 / 1024));

if ($name) {
// If name presented, show downloads for that name
$this->getOutput()->writeln(sprintf('%s %dMB', array_pop($itemKeyChunks), $item['Size'] / 1024 / 1024));
} else {
// Otherwise show uniqued list of available names
if (!in_array($itemKeyChunks[0], $names)) {
$names[] = $itemKeyChunks[0];
$this->getOutput()->writeln($itemKeyChunks[0]);
}
}
}

if (!$results->count()) {
Expand Down

0 comments on commit 28fa9ba

Please sign in to comment.